//////////////////////////////////////////////////////
// Locale manager ////////////////////////////////////
//////////////////////////////////////////////////////

localeManager = {
	
	//////////////////////////////////////////////
	//////// CONFIGURATION DEFAULT VALUES ////////
	//////////////////////////////////////////////
	
	locale: "de_AT"
	,debugMode: false
	
	,localeSrings: {
		de_AT: {
			matsplayer: {
				title: 				"Flash Inhalte k&ouml;nnen nicht angezeigt werden."
				,header: 			"Bitte &uuml;berpr&uuml;fen Sie:"
				,text1: 			"- ob Java Script von Ihrem Browser zugelassen wird."
				,text2: 			"- ob Sie die richtige Flash Player Version installiert haben."
				,text3: 			"Ben&ouml;tigte Version:"
				,text4: 			"Gefundene Version:"
				,text5:				"Falls Ihre Flash Player Version nicht aktuell ist und der automatische Update Vorgang nicht startet, klicken Sie bitte auf den Download Link, um die letzte Flash Player Version von Adobe herunterzuladen:"
			}
			,onlineLearnPath: {
				contentsBtn: 		"Inhalte"
				,learnpathBtn: 		"Lernpfad"
				,reportBtn: 		"Auswertung"
				,reportHelpText: 	"W&auml;hlen Sie rechts das Kapitel von dem Sie die Auswertung einsehen wollen."
				,overviewTitle: 	"Auswertung"
				,titleHeader: 		"Lektions Titel"
				,maxHeader: 		"Max Punkte"
				,rawHeader: 		"Ihre Punkte"
				,successHeader: 	"Erledigt"
				,completionHeader: 	"Ge&ouml;ffnet"
			}
		}
		,en_US: {	
			matsplayer: {
				title: 				"Flash based content cannot be displayed."
				,header: 			"Please check if:"
				,text1:				"- Javascript is allowed by your browser."
				,text2:				"- you have installed the correct Flash Player version."
				,text3:				"Required version:"
				,text4:				"Version found:"
				,text5:				"If your Flash Player is not current and the automatic update does not start, please click on the download link to download the latest Flash Player version from Adobe:"
			}	
			,onlineLearnPath: {
				contentsBtn:		"Contents"
				,learnpathBtn:		"Learnpath"
				,reportBtn:			"Results"
				,reportHelpText:	"Choose a chapter on the right side to view lesson results."
				,overviewTitle:		"Results"
				,titleHeader:		"Lesson Title"
				,maxHeader:			"Max Points"
				,rawHeader:			"Your Points"
				,successHeader:		"Done"
				,completionHeader:	"Open"
			}
		}
		,fr_FR: {	
			matsplayer: {
				title: 				"Les contenus Flash ne s’affichent pas."
				,header: 			"Veuillez vérifier:"
				,text1:				"- si le Script Java est autorisé par votre navigateur"
				,text2:				"- si vous avez installé la bonne version de Flash Player"
				,text3:				"Version nécessaire:"
				,text4:				"Version trouvée:"
				,text5:				"Si la version de votre Flash Player n’est pas actuelle et que l’opération de mise à jour automatique ne démarre pas, veuillez cliquer sur le lien de téléchargement pour télécharger la dernière version Flash Player d’Adobe:"
			}	
			,onlineLearnPath: {
				contentsBtn:		"Contents"
				,learnpathBtn:		"Learnpath"
				,reportBtn:			"Results"
				,reportHelpText:	"Choose a chapter on the right side to view lesson results."
				,overviewTitle:		"Results"
				,titleHeader:		"Lesson Title"
				,maxHeader:			"Max Points"
				,rawHeader:			"Your Points"
				,successHeader:		"Done"
				,completionHeader:	"Open"
			}
		}
	}
	
	////////////////////////////////////////////////////////////////////
	////////////// Public methods //////////////////////////////////////
	////////////////////////////////////////////////////////////////////
	
	// Initialization interests of params either from LMS or if present from configParams
    ,initializationInterestParams : [
    		{paramAlias: "locale",    		prop: "locale",		target:"localeManager"}
			,{paramAlias: "debugMode",    	prop: "debugMode",	target:"localeManager"}
			]
			
	// Init the locale either from config or from value given to the function
	,initialize: function(locale){
		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 localeManager [param:" + param + " value:" + prop + " target:" + tar + "]");
				if (typeof param === "string" && typeof prop === "string" 
					&& typeof tar === "string" && tar == "localeManager") {
					// 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 localeManager is set to " + configParams[param]);
						}
					}
				}
			}
		}
		// Overwrite locale if the value is given to the function
		if (typeof locale !== "undefined" && locale != "") {
			this.locale = locale;
		}
	}
	
	// Returns the string of a package, Id and locale
	,getStringById : function(bundle, componentId, locale){
		if (typeof locale === "undefined" || locale == ""){
			locale = this.locale;
		}
		var currentString = this.localeSrings[locale][bundle][componentId];
	    if(typeof currentString !== "undefined" && currentString != ""){
	    	return currentString;                                                     
		}else{
			this.trace("ERROR: Not able to get string from locale: "+locale+" bundle: "+bundle+" Id: "+componentId);
			return "STRING NOT FOUND";
		}	
	}
	
	// Set the locale strings depending on element id
	,applyLocale : function(bundle, locale){
		if (typeof locale === "undefined" || locale == ""){
			locale = this.locale;
		}
		var arrayObject = this.localeSrings[locale][bundle];
		for(var id in arrayObject){
		   var currentString = arrayObject[id];
		   if(typeof currentString !== "undefined" && typeof id !== "undefined"){
		      var currentHTMLElement = document.getElementById(id);
		      if(currentHTMLElement != null){
		         currentHTMLElement.innerHTML = currentString;
		      }else{
			  	this.trace("WARNING: Not able to find component with id: "+id+" to put locale string");	
			  } 
		   }                                                    
		}	
	}
	
	// Trace for debug
	,trace : function(info){
		if (this.debugMode === true) {
			var tracePrefix = "[localeManager] ";
			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
localeManager = window.localeManager || {};