// to avoid propagandation of not needed variables in static pages
if (typeof _domain_path_to_ecms_resources_ == 'undefined') {
	_domain_path_to_ecms_resources_ = null;
	_backend_language_ = null;
	_domain_path_to_ecms_ = null;
	_pathToEditor_ = null;
}

var scripts = {
  Version: '0.1',
  // every script to be loaded must be an associative array with path (abs. to domain) as value
  scriptPaths:{
	'translations': _domain_path_to_ecms_resources_+'js'+_dirSep_+'i18n'+_dirSep_+_backend_language_+_dirSep_, 
	'core': _domain_path_to_ecms_resources_+'js'+_dirSep_,
  'editor': _domain_path_to_ecms_+_pathToEditor_,
	'resource':_domain_path_to_resources_+'js'+_dirSep_
  },
  require: function(js) {
    try{ //alert(js);
      // should work in all browser
      document.write('<script type="text/javascript" src="'+js+'" charset="UTF-8"><\/script>');
    } catch(e) {
      // for xhtml+xml served content, fall back to DOM methods
      var script = document.createElement('script');
      script.type = 'text/javascript';
      script.charset = 'UTF-8';
      script.src = js; 
      document.getElementsByTagName('body')[0].appendChild(script);
    }
  },
  load: function() {
		// make sure every needed variable is defined
    if((typeof _domain_path_to_ecms_resources_ == 'undefined') || (typeof _dirSep_ == 'undefined') ||
       (typeof lang == 'undefined') || (typeof _backend_language_ == 'undefined') ||
       (typeof scriptsToLoad == 'undefined'))
       alert("Some or all needed variables for scripts " + scripts.Version + " are not defined!");
		for (var scriptGroup in scriptsToLoad){ 
				if(typeof scriptsToLoad[scriptGroup] === 'object'){ 
					for(var script in scriptsToLoad[scriptGroup]) 
						if(scriptsToLoad[scriptGroup][script] === true) scripts.require(scripts.scriptPaths[scriptGroup] + script + '.js');	
				}
		}
  }
};
scripts.load();
