//////////////////////////////////////////////////////
// Wrapper for matsplayer ////////////////////////////
//////////////////////////////////////////////////////

matsplayer = {	
	initializationInterestParams:  [
		{paramAlias: "userName", 		prop: "userName"}
		,{paramAlias: "userId", 		prop: "userId"}
		,{paramAlias: "userPoints", 	prop: "lastUserPoints"}
		,{paramAlias: "location", 		prop: "lastLocation" }
		,{paramAlias: "userAudioPref", 	prop: "lastAudioPref"}
		,{paramAlias: "suspendData", 	prop: "suspendData"}
		,{paramAlias: "masteryScore", 	prop: "masteryScore"}
	]
}

//////////////////////////////////////////////////////
// Wrapper for etesting ////////////////////////////
//////////////////////////////////////////////////////

etestingplayer = {
	initializationInterestParams:  [
		{paramAlias: "userName", 		prop: "userName"}
		,{paramAlias: "userId", 		prop: "userId"}
		,{paramAlias: "timeLimit", 		prop: "timeLimit"}
		,{paramAlias: "masteryScore",	prop: "masteryScore"}
		,{paramAlias: "suspendData", 	prop: "suspendData"}
	]
}
////////////////////////////////////////////////////////////////
//////////// PLAYER WRAPPERS SHARED METHODS ////////////////////
////////////////////////////////////////////////////////////////

////////////////
// INITIALIZE //
////////////////
etestingplayer.initialize = 
matsplayer.initialize = function(){
	// Requires scormManager to work!
	if(typeof scormManager.getParam !== "function"){return false;}
	for(var i in this.initializationInterestParams){
		var param = this.initializationInterestParams[i].paramAlias;
		var prop = this.initializationInterestParams[i].prop; 
		this.trace("init param:"+param+" value:"+prop);
		if(typeof param === "string" && typeof prop === "string"){		
			var value = scormManager.getParam(param, prop);
			this.trace("initialised parameter:"+param+" with value:"+value);
			if(typeof scormManager[prop] !== "undefined"){
				this.trace("setting value on scormManager");
				scormManager[prop] = value;
				this.trace("setted "+prop+" to:"+scormManager[prop]);
			}
		}
	}
}
///////////////////
// CLOSE CONTENT //
///////////////////
etestingplayer.closeContent = 
matsplayer.closeContent = function(){
	if(typeof scormManager.closeContent === "function"){
		this.trace("executing scormManager.closeContent from player wrapper");
		scormManager.closeContent();
	}
}
//////////////////////////////////////////////////////
// Signals sent from the player //////////////////////
//////////////////////////////////////////////////////
// param should come as a string
etestingplayer.setSessionLocation = 
matsplayer.setSessionLocation = function(location){
	if (typeof scormManager.setParam !== "function"){return false}
	if (typeof location !== "string"){location = String(location)}
	scormManager.setParam("location", location);
}
// no params for this method. Session duration will be calculated based on the interval SCORM API connected - Current time 
etestingplayer.setSessionDuration = 
matsplayer.setSessionDuration = function(){
	if (typeof scormManager.setParam !== "function"){return false}
	scormManager.setParam("duration");
}
// No params for this method
etestingplayer.commitChanges = 
matsplayer.commitChanges = function(){
	if (typeof scormManager.saveData !== "function"){return false}
	scormManager.saveData();
}
// param should come as a number
etestingplayer.setUserScore = 
matsplayer.setUserScore = function(userScore){
	if (typeof scormManager.setParam !== "function"){return false}
	if (typeof userScore !== "number"){userScore = Number(userScore)}
	scormManager.setParam("userPoints", userScore);
}
// no params for this method. Lesson status will be calculated based on minPoints, maxPoints, and userPoints
etestingplayer.setLessonStatus = 
matsplayer.setLessonStatus = function(){
	if (typeof scormManager.setParam !== "function"){return false}
	scormManager.setParam("status");	
}
// param should come as a number
etestingplayer.setMaxPoints = 
matsplayer.setMaxPoints = function(maxPoints){
	if (typeof scormManager.setParam !== "function"){return false}
	if (typeof userScore !== "maxPoints"){maxPoints = Number(maxPoints)}
	scormManager.setParam("maxPoints", maxPoints);
}
// param should come as a number
etestingplayer.setMinPoints = 
matsplayer.setMinPoints = function(minPoints){
	if (typeof scormManager.setParam !== "function"){return false}
	if (typeof minPoints !== "number"){minPoints = Number(minPoints)}
	scormManager.setParam("minPoints", minPoints);
}
// soundStatus is "ON"|"OFF"
// if no param provided or incorrect type, puts the audio "ON"
etestingplayer.setAudioPref = 
matsplayer.setAudioPref = function(soundStatus){
	if (typeof scormManager.setParam !== "function"){return false}
	if (typeof soundStatus !== "string"){soundStatus = "ON"}
	scormManager.setParam("userAudioPref", soundStatus);
}
// Suspend data (for notes)
etestingplayer.setUserNotes = 
matsplayer.setUserNotes = function(userNotesStr){
	if (typeof scormManager.setParam !== "function"){return false}
	if (typeof userNotesStr !== "string"){userNotesStr = ""}
	scormManager.setParam("suspendData", userNotesStr);
}
etestingplayer.setItemsOrder = function(itemsOrderStr){
	if (typeof scormManager.setParam !== "function"){return false}
	if (typeof itemsOrderStr !== "string"){itemsOrderStr = ""}
	scormManager.setParam("suspendData", itemsOrderStr);
}
etestingplayer.forcePassedLesson = 
matsplayer.forcePassedLesson = function(){
	if (typeof scormManager.setParam !== "function"){return false}
	matsplayer.setMaxPoints(1);
	matsplayer.setMinPoints(0);
	matsplayer.setUserScore(1);
	scormManager.setParam("status", "completed");
	matsplayer.setMaxPoints = 
	matsplayer.setMinPoints = 
	matsplayer.setUserScore = function(points){return false;}
}