//////////////////////////////////////////////////////
// bitLib import set /////////////////////////////////
//////////////////////////////////////////////////////

importManager = {
	
	//////////////////////////////////////////////
	//////// CONFIGURATION DEFAULT VALUES ////////
	//////////////////////////////////////////////
	
	debugMode : false
	,locale : "de_AT"
	
	// importResources default values, including all present files to be sure all objects are imported
	,importResources : [
		{src: "wrapper/player/matsplayer.js",							type: "text/javascript"}
		,{src: "time/timeManager.js",									type: "text/javascript"}			
		,{src: "wrapper/SCORM/scormManager.js",							type: "text/javascript"}
		,{src: "3rdParty/swfobject_v1.5.1/swfobject.js", 				type: "text/javascript"}
		,{src: "3rdParty/swfobject_v2.2/swfobject.js", 					type: "text/javascript"}
		,{src: "3rdParty/prototype_v1.6.1/prototype1-6-1.js", 			type: "text/javascript"}
		,{src: "3rdParty/mootools_v1.2.4/mootools-1.2.4-core-yc.js",	type: "text/javascript"}			
		,{src: "3rdParty/mootools_v1.2.4/mootools-1.2.4.4-more.js",		type: "text/javascript"}
		,{src: "3rdParty/json_v2/json2.js", 							type: "text/javascript"}
		,{src: "3rdParty/yahoo_v2.8.1/yahoo-min.js",					type: "text/javascript"}			
		,{src: "3rdParty/yahoo_v2.8.1/json-min.js",						type: "text/javascript"}
		,{src: "wrapper/player/courseManager.js",						type: "text/javascript"}
		,{src: "locale/de_AT/strings.js", 								type: "text/javascript"}							
		,{src: "locale/localeManager.js",								type: "text/javascript"}
		,{src: "utils.js",												type: "text/javascript"}
		,{src: "config/configParams.js", 								type: "text/javascript"}
		,{src: "config/customConfigParams.js", 							type: "text/javascript"}
	]
	
	////////////////////////////////////////////////////////////////////
	////////////// Public methods //////////////////////////////////////
	////////////////////////////////////////////////////////////////////
	
	,getImportResources : function(resource){
		if (typeof resource !== "undefined" && typeof importResources !== "undefined") {
			switch(resource){
				case "lesson" : this.importResources = importResources.lesson;
				break;
				case "etest" : this.importResources = importResources.etest;
				break;
				case "material" : this.importResources = importResources.material;
				break;
				case "olp" : this.importResources = importResources.olp;
				break;
				case "olpNoContent" : this.importResources = importResources.olpNoContent;
				break;
				case "olpContent" : this.importResources = importResources.olpContent;
				break;
				default : // default value is used
				break; 
			}
		}
		this.trace("ImportResources are " + resource);
	}
	
	,importScripts : function(resource){
		this.initialize();
		this.getImportResources(resource);
		addCode.addImportRecourcesToHeader("path", this.importResources);
		/*
		for(var j in this.importResources)
		{
			addCode.toHeader("path", this.importResources[j].src, this.importResources[j].type);
		}
		*/
	}
	
	// Initialization interests of params from configParams
    ,initializationInterestParams : [
    		{paramAlias: "locale",    		prop: "locale",		target:"importManager"}
			,{paramAlias: "debugMode",    	prop: "debugMode",	target:"importManager"}
	]
			
	// Init the locale either from config or from value given to the function
	,initialize: function(){
		if(window.configParams !== "undefined" || configParams != {}){
			for (var i in this.initializationInterestParams) {
				var param = this.initializationInterestParams[i].paramAlias;
				var prop = this.initializationInterestParams[i].prop;
				var tar = this.initializationInterestParams[i].target;
				//this.trace("init importManager [param:" + param + " value:" + prop + " target:" + tar + "]");
				if (typeof param === "string" && typeof prop === "string" 
					&& typeof tar === "string" && tar == "importManager") {
					// Take the matching config value
					for (var j in configParams) {
						var configValue = String(j);
						if (configValue == param || configValue == prop) {
							this[prop] = configParams[param] || configParams[prop];
							this.trace("Param " + param + " of importManager is set to " + configParams[param]);
						}
					}
				}
			}
		}
		// Write locale to importRecources to get the right locale strings
		importResources.locale = this.locale;
	}
	
	// Trace for debug
	,trace : function(info){
		if (this.debugMode === true) {
			var tracePrefix = "[importManager] ";
			if (window.console && window.console.firebug) { // Firebug
				if (typeof info == "string") {
					console.log(tracePrefix + info);
				}
				else {
					console.debug(tracePrefix + info);
				}
			} else if (window.console) { // Safari
				if (typeof info == "string") {
					window.console.log(tracePrefix + info);
				}
				else {
				//window.console.debug(tracePrefix+info);
				}
			}
			else { // Ugly browsers a.k.a IE any version
				alert(tracePrefix + info.toString());
			}
		}
	}
}

// Be sure object is present
importManager = window.importManager || {}; 