var Loader = (function() {
  var _el_name = arguments[0] || 'js-loader';
  var _el = document.getElementById( _el_name);

  if (!_el) {
    throw new Error('Loader element "' +  _el_name + '" not found');
  }
  var _path = _el.src.replace(/loader\.js(\?.*)?$/, '');

  return {
    include: function(files, dir) {
      var path = _path + (dir ? dir + '/' : '');

      if (typeof files == 'string') {
        files = [files];
      }
      for (var i = 0; i < files.length; i++) {
        document.write('<script type="text/javascript" src="' + path + files[i] + '.js"></script>');
      }
      return this;
    },
    load: function() {
      var includes = _el.src.match(/[\?&].*load=([^&]+)/);
      if (includes) {
        this.include(includes[1].split(','));
      }
      return this;
    }
  };
});

var loader = new Loader('loader').include([
  'calendar',
  'lang/calendar-de',
  'calendar-setup'
], 'jscalendar');

loader.include('jquery');
loader.include([
  'dimensions',
  'jquery.form',
  'jquery.validate',
  'jquery.bgiframe.min',
  'jquery.autocomplete'
], 'jQuery/plugins');

loader.include([
  'common',
  'css',
  'standardista-table-sorting'
], 'table-sorting');

loader.include('firebug', 'firebug');
loader.include('app');
