<!--
var undefined;
function confirmSWVersion () {
	getSWVersion()
	var tMajorVersion = 11;
	var tMinorVersion = 5;
	var tShockwaveFound = 0;
	if (tVersionString != "" && tVersionString != undefined) {
		tArr = tVersionString.split(".");
		var tMajorVersionString = tArr[0];
		var tMinorVersionString = tArr[1];
		if (parseInt(tMajorVersionString) >= tMajorVersion) {
			if (tMinorVersion > 0 && parseInt(tMajorVersionString) == tMajorVersion) {
				if (parseInt(tMinorVersionString) >= tMinorVersion) {
					tShockwaveFound = 1;
				}
			} else {
				tShockwaveFound = 1;
			}
		}
	}
	return tShockwaveFound;
}
function getSWVersion() {
	tVersionString = ""
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-director"] && navigator.mimeTypes["application/x-director"].enabledPlugin) {
		if (navigator.plugins && navigator.plugins["Shockwave for Director"] && (tVersionIndex = navigator.plugins["Shockwave for Director"].description.indexOf(".")) != - 1) {
			tVersionString = navigator.plugins["Shockwave for Director"].description.substring(tVersionIndex-2, tVersionIndex+2);
		}
	} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0 )) {
		document.write('<SCRIPT LANGUAGE=VBScript\> \n');
		document.write('on error resume next \n');
		document.write('set tSWControl = CreateObject("SWCtl.SWCtl") \n');
		document.write('if IsObject(tSWControl) then \n');
		document.write('tVersionString = tSWControl.ShockwaveVersion("") \n');
		document.write('end if\n');
		document.write('</SCRIPT\> \n');
	}
}
function embedShockwave(tPath, tStartMovie, tRedirect, tJumpStart, tSw2, tSw3, tSw4, tLangs) {
	embedShockwaveV2("", "", tJumpStart, tLangs, tSw2, tSw3, tSw4);
}
function embedShockwaveV2(tScormID, tEmbedID, tJumpStart, tLangs, tSw2, tSw3, tSw4) {
	pScorm = pipwerks.SCORM.API.getHandle()
	if (tLangs==undefined) {tLangs="en"}
	if (tScormID.charAt(0)=="$") {
		if (tScormID.indexOf("ltl")>=0) {
tMoviePath = "http://files.anywhere.sunflowerlearning.com.s3.amazonaws.com/"+tScormID.substr(1) + "/ngpreloader.dcr";
		} else {
tMoviePath = "http://files.anywhere.sunflowerlearning.com.s3.amazonaws.com/"+tScormID.substr(1) + "/preloader.dcr";
	}
	tScormID = "";
	} else if (tScormID=="startx") {
tMoviePath = "http://files.anywhere.sunflowerlearning.com.s3.amazonaws.com/startX.dcr";
		tScormID = "";
	} else {
tMoviePath = "http://files.anywhere.sunflowerlearning.com.s3.amazonaws.com/start.dcr";
}
	if (tJumpStart==undefined) {tJumpStart=""};
if(confirmSWVersion()) {
	var tElement = document.getElementById("sw");
	var tHTML = '<OBJECT classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000"';
	tHTML = tHTML + ' codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=11,5,0,0"' ;
	tHTML = tHTML + ' ID="sfs" WIDTH="100%" HEIGHT="100%" NAME="sfs"> ';
	tHTML = tHTML + '<PARAM NAME="src" VALUE="' + tMoviePath + '"> ';
	tHTML = tHTML + '<PARAM NAME="swStretchStyle" VALUE="stage"> ';
	tHTML = tHTML + '<PARAM NAME="PlayerVersion" VALUE="11"> ';
	tHTML = tHTML + "<PARAM NAME='sw1' VALUE='" + tJumpStart + "'> ";
	if (tSw2!=undefined) {tHTML = tHTML + "<PARAM NAME='sw2' VALUE='" + tSw2 + "'> "};
	if (tSw3!=undefined) {tHTML = tHTML + "<PARAM NAME='sw3' VALUE='" + tSw3 + "'> "};
	if (tSw4!=undefined) {tHTML = tHTML + "<PARAM NAME='sw4' VALUE='" + tSw4 + "'> "};
	if (tLangs!=undefined) {tHTML = tHTML + "<PARAM NAME='sw5' VALUE='" + tLangs + "'> "};
	if (tScormID.length>5) {tHTML = tHTML + "<PARAM NAME='sw7' VALUE='" + tScormID + ";" + tEmbedID + "'> "};
	if (pScorm!=null) {tHTML = tHTML + "<PARAM NAME='sw9' VALUE='1'> "};
	tHTML = tHTML + '<PARAM NAME="swRemote" VALUE="';
	tHTML = tHTML + "swSaveEnabled='false' swVolume='true' swRestart='true' swPausePlay='true' swFastForward='true' swContextMenu='true'";
	tHTML = tHTML + '">\n' ;
	tHTML = tHTML + '<EMBED SRC="' + tMoviePath + '"';
	tHTML = tHTML + ' bgColor="#E1ECE8" WIDTH="100%" HEIGHT="100%" NAME="sfs" swStretchStyle="stage" ';
	tHTML = tHTML + "sw1='" + tJumpStart + "' ";
	if (tSw2!=undefined) {tHTML = tHTML + "sw2='" + tSw2 + "' "};
	if (tSw3!=undefined) {tHTML = tHTML + "sw3='" + tSw3 + "' "};
	if (tSw4!=undefined) {tHTML = tHTML + "sw4='" + tSw4 + "' "};
	if (tLangs!=undefined) {tHTML = tHTML + "sw5='" + tLangs + "' "};
	if (tScormID.length>5) {tHTML = tHTML + "sw7='" + tScormID + ";" + tEmbedID + "' "};
	if (pScorm!=null) {tHTML = tHTML + "sw9='1' "};
	tHTML = tHTML + 'swRemote="';
	tHTML = tHTML + "swSaveEnabled='false' swVolume='true' swRestart='true' swPausePlay='true' swFastForward='true' swContextMenu='true'";
	tHTML = tHTML + '"';
	tHTML = tHTML + ' TYPE="application/x-director" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveDirector" PlayerVersion=11>';
	tHTML = tHTML + '</EMBED>';
	tHTML = tHTML + '</OBJECT>';
	tElement.innerHTML = tHTML
} else {
	window.location = "http://anywhere.sunflowerlearning.com/dswmedia/shockwaveWeb.html"//tPath + "shockwave" + tRedirect + ".html";
}
setMovieAlias();
}
// SCORM HANDLES
function SCORMCommand(methodName, arg1, arg2, arg3) {
	var tRes = "",
	trace = pipwerks.UTILS.trace;
	trace("running Scorm command from Shockwave: " + methodName)
	switch (methodName) {
		case "getInitialData":
		SCORMset("cmi.exit","suspend")
		//if (SCORMget("cmi.Completion_status") != "completed") {
		//	SCORMset("cmi.completion_status", "incomplete")
		SCORMset("cmi.success_status", "unknown")
		//}
		var tCount = Number(SCORMget("cmi.interactions._count"))
		if (tCount>0) {
			tTime = SCORMget("cmi.session_time")
			tRes = '["' + tTime + '",'
			var tNameEntered = false
			for (var i = 0; i<tCount; i++) {
				var tS = "cmi.interactions." + i + "."
				var tId = SCORMget(tS+"id")
				if (tId == 3000001) {tNameEntered = true}
				tRes += "[#nIndex:" + i + ", #nId:" + tId + ', #nResponse:"' + SCORMget(tS+"learner_response") + '"]'
				if (i<tCount-1) {tRes += ","}
			}
			if (!tNameEntered) {
				tRes += ',[#nIndex:#none, #nId:3000001, #nResponse:"' + SCORMget("cmi.learner_name") + '"]'
			}
			tRes += "]"
		} else {
			tRes = '["0:0:0", [#nIndex:#none, #nId:3000001, #nResponse:"' + SCORMget("cmi.learner_name") + '"]]'
		}
		//alert(tRes)
		sendResult(methodName, tRes, true)
		break
		case "setInteraction":
		var tData = arg1.split(";")
		var tInt = "cmi.interactions." + tData[0] + "."
		SCORMset(tInt + "id", ""+tData[1])
		SCORMset(tInt + "type", "fill-in")
		SCORMset(tInt + "learner_response", ""+tData[2])
		SCORMset(tInt + "result", ""+tData[3])
		SCORMset(tInt + "description", ""+tData[4])
		break
		case "submitScore":
		SCORMCommand("setInteraction", SCORMget("cmi.interactions._count") + ";3000002;Submit;neutral;Quiz submitted as complete")
		SCORMset("cmi.score.min", 0)
		SCORMset("cmi.score.max", Number(arg2))
		SCORMset("cmi.score.raw", Number(arg1))
		SCORMset("cmi.score.scaled", (Number(arg1)/Number(arg2)))
		SCORMset("cmi.session_time", arg3)
		//SCORMset("cmi.completion_status", "completed")
		SCORMset("cmi.success_status", "unknown")
		SCORMsave()
		sendResult(methodName, "true", false)
		break
		case "Commit":
		SCORMset("cmi.session_time", arg1)
		sendResult(methodName, SCORMsave(), false)
		break
		case "Initialize":
		sendResult(methodName, SCORMinit(), false)
		break
		case "Terminate":
		sendResult(methodName, SCORMquit(), false)
		break
	}
}
var gTheMovie;
function setMovieAlias() {
	if(navigator.appName == "Microsoft Internet Explorer") {
		gTheMovie = sfs;
	} else {
		gTheMovie = document.sfs;
	}
}
function sendResult(tFn, tRes, tAsValue) {
	var tQuote = (tAsValue ? '' : '"')
	pipwerks.UTILS.trace("Sending " + tFn + "; " + tRes)
	gTheMovie.EvalScript('[#' + tFn + ', ' + tQuote + tRes + tQuote + ']')
}

/* =====================================================================================

SCORM wrapper v1.1.7 by Philip Hutchison, May 2008 (http://pipwerks.com).

Copyright (c) 2008 Philip Hutchison
MIT-style license. Full license text can be found at
http://www.opensource.org/licenses/mit-license.php

This wrapper is designed to work with both SCORM 1.2 and SCORM 2004.

Based on APIWrapper.js, created by the ADL and Concurrent Technologies
Corporation, distributed by the ADL (http://www.adlnet.gov/scorm).

SCORM.API.find() and SCORM.API.get() functions based on ADL code,
modified by Mike Rustici (http://www.scorm.com/resources/apifinder/SCORMAPIFinder.htm),
further modified by Philip Hutchison

======================================================================================== */


var pipwerks = {};									//pipwerks 'namespace' helps ensure no conflicts with possible other "SCORM" variables
pipwerks.UTILS = {};								//For holding UTILS functions
pipwerks.debug = { isActive: true }; 				//Enable (true) or disable (false) for debug mode

pipwerks.SCORM = {									//Define the SCORM object
	version:    null,              					//Store SCORM version.
	handleCompletionStatus: true,					//Whether or not the wrapper should automatically handle the initial completion status
	handleExitMode: true,							//Whether or not the wrapper should automatically handle the exit mode
	API:        { handle: null,
	isFound: false },					//Create API child object
	connection: { isActive: false },				//Create connection child object
	data:       { completionStatus: null,
	exitStatus: null },				//Create data child object
	debug:      {}                 					//Create debug child object
};



/* --------------------------------------------------------------------------------
pipwerks.SCORM.isAvailable
A simple function to allow Flash ExternalInterface to confirm
presence of JS wrapper before attempting any LMS communication.

Parameters: none
Returns:    Boolean (true)
----------------------------------------------------------------------------------- */

pipwerks.SCORM.isAvailable = function(){
	return true;
};



// ------------------------------------------------------------------------- //
// --- SCORM.API functions ------------------------------------------------- //
// ------------------------------------------------------------------------- //


/* -------------------------------------------------------------------------
pipwerks.SCORM.API.find(window)
Looks for an object named API in parent and opener windows

Parameters: window (the browser window object).
Returns:    Object if API is found, null if no API found
---------------------------------------------------------------------------- */

pipwerks.SCORM.API.find = function(win){

	var API = null,
	findAttempts = 0,
	findAttemptLimit = 500,
	traceMsgPrefix = "SCORM.API.find",
	trace = pipwerks.UTILS.trace,
	scorm = pipwerks.SCORM;

	while ((!win.API && !win.API_1484_11) &&
	(win.parent) &&
	(win.parent != win) &&
	(findAttempts <= findAttemptLimit)){

		findAttempts++;
		win = win.parent;

	}

	if(scorm.version){											//If SCORM version is specified by user, look for specific API

		switch(scorm.version){

			case "2004" :

			if(win.API_1484_11){

				API = win.API_1484_11;

			} else {

				trace(traceMsgPrefix +": SCORM version 2004 was specified by user, but API_1484_11 cannot be found.");

			}

			break;

			case "1.2" :

			if(win.API){

				API = win.API;

			} else {

				trace(traceMsgPrefix +": SCORM version 1.2 was specified by user, but API cannot be found.");

			}

			break;

		}

	} else {													//If SCORM version not specified by user, look for APIs

		if(win.API_1484_11) {									//SCORM 2004-specific API.

			scorm.version = "2004";								//Set version
			API = win.API_1484_11;

		} else if(win.API){										//SCORM 1.2-specific API

			scorm.version = "1.2";								//Set version
			API = win.API;

		}

	}

	if(API){

		trace(traceMsgPrefix +": API found. Version: " +scorm.version);
		trace("API: " +API);

	} else {

		trace(traceMsgPrefix +": Error finding API. \nFind attempts: " +findAttempts +". \nFind attempt limit: " +findAttemptLimit);

	}

	return API;

};


/* -------------------------------------------------------------------------
pipwerks.SCORM.API.get()
Looks for an object named API, first in the current window's frame
hierarchy and then, if necessary, in the current window's opener window
hierarchy (if there is an opener window).

Parameters:  None.
Returns:     Object if API found, null if no API found
---------------------------------------------------------------------------- */

pipwerks.SCORM.API.get = function(){

	var API = null,
	win = window,
	find = pipwerks.SCORM.API.find,
	trace = pipwerks.UTILS.trace;

	if(win.parent && win.parent != win){

		API = find(win.parent);

	}

	if(!API && win.top.opener){

		API = find(win.top.opener);

	}

	if(API){

		pipwerks.SCORM.API.isFound = true;

	} else {

		trace("API.get failed: Can't find the API!");

	}

	return API;

};


/* -------------------------------------------------------------------------
pipwerks.SCORM.API.getHandle()
Returns the handle to API object if it was previously set

Parameters:  None.
Returns:     Object (the pipwerks.SCORM.API.handle variable).
---------------------------------------------------------------------------- */

pipwerks.SCORM.API.getHandle = function() {

	var API = pipwerks.SCORM.API;

	if(!API.handle && !API.isFound){

		API.handle = API.get();

	}

	return API.handle;

};



// ------------------------------------------------------------------------- //
// --- pipwerks.SCORM.connection functions --------------------------------- //
// ------------------------------------------------------------------------- //


/* -------------------------------------------------------------------------
pipwerks.SCORM.connection.initialize()
Tells the LMS to initiate the communication session.

Parameters:  None
Returns:     Boolean
---------------------------------------------------------------------------- */

pipwerks.SCORM.connection.initialize = function(){

	var success = false,
	scorm = pipwerks.SCORM,
	completionStatus = pipwerks.SCORM.data.completionStatus,
	trace = pipwerks.UTILS.trace,
	makeBoolean = pipwerks.UTILS.StringToBoolean,
	debug = pipwerks.SCORM.debug,
	traceMsgPrefix = "SCORM.connection.initialize ";

	trace("connection.initialize called.");

	if(!scorm.connection.isActive){

		var API = scorm.API.getHandle(),
		errorCode = 0;

		if(API){

			switch(scorm.version){
				case "1.2" : success = makeBoolean(API.LMSInitialize("")); break;
				case "2004": success = makeBoolean(API.Initialize("")); break;
			}

			if(success){

				//Double-check that connection is active and working before returning 'true' boolean
				errorCode = debug.getCode();

				if(errorCode !== null && errorCode === 0){

					scorm.connection.isActive = true;

					if(scorm.handleCompletionStatus){

						//Automatically set new launches to incomplete
						completionStatus = pipwerks.SCORM.status("get");

						if(completionStatus){

							switch(completionStatus){

								//Both SCORM 1.2 and 2004
								case "not attempted": pipwerks.SCORM.status("set", "incomplete"); break;

								//SCORM 2004 only
								case "unknown" : pipwerks.SCORM.status("set", "incomplete"); break;

								//Additional options, presented here in case you'd like to use them
								//case "completed"  : break;
								//case "incomplete" : break;
								//case "passed"     : break;	//SCORM 1.2 only
								//case "failed"     : break;	//SCORM 1.2 only
								//case "browsed"    : break;	//SCORM 1.2 only

							}

						}

					}

				} else {

					success = false;
					trace(traceMsgPrefix +"failed. \nError code: " +errorCode +" \nError info: " +debug.getInfo(errorCode));

				}

			} else {

				errorCode = debug.getCode();

				if(errorCode !== null && errorCode !== 0){

					trace(traceMsgPrefix +"failed. \nError code: " +errorCode +" \nError info: " +debug.getInfo(errorCode));

				} else {

					trace(traceMsgPrefix +"failed: No response from server.");

				}
			}

		} else {

			trace(traceMsgPrefix +"failed: API is null.");

		}

	} else {

		trace(traceMsgPrefix +"aborted: Connection already active.");

	}

	return success;

};


/* -------------------------------------------------------------------------
pipwerks.SCORM.connection.terminate()
Tells the LMS to terminate the communication session

Parameters:  None
Returns:     Boolean
---------------------------------------------------------------------------- */

pipwerks.SCORM.connection.terminate = function(){

	var success = false,
	scorm = pipwerks.SCORM,
	exitStatus = pipwerks.SCORM.data.exitStatus,
	completionStatus = pipwerks.SCORM.data.completionStatus,
	trace = pipwerks.UTILS.trace,
	makeBoolean = pipwerks.UTILS.StringToBoolean,
	debug = pipwerks.SCORM.debug,
	traceMsgPrefix = "SCORM.connection.terminate ";


	if(scorm.connection.isActive){

		var API = scorm.API.getHandle(),
		errorCode = 0;

		if(API){

			if(scorm.handleExitMode && !exitStatus){

				if(completionStatus !== "completed" && completionStatus !== "passed"){

					switch(scorm.version){
						case "1.2" : success = SCORMset("cmi.core.exit", "suspend"); break;
						case "2004": success = SCORMset("cmi.exit", "suspend"); break;
					}

				} else {

					switch(scorm.version){
						case "1.2" : success = SCORMset("cmi.core.exit", "logout"); break;
						case "2004": success = SCORMset("cmi.exit", "normal"); break;
					}

				}

			}

			switch(scorm.version){
				case "1.2" : success = makeBoolean(API.LMSFinish("")); break;
				case "2004": success = makeBoolean(API.Terminate("")); break;
			}

			if(success){

				scorm.connection.isActive = false;

			} else {

				errorCode = debug.getCode();
				trace(traceMsgPrefix +"failed. \nError code: " +errorCode +" \nError info: " +debug.getInfo(errorCode));

			}

		} else {

			trace(traceMsgPrefix +"failed: API is null.");

		}

	} else {

		trace(traceMsgPrefix +"aborted: Connection already terminated.");

	}

	return success;

};



// ------------------------------------------------------------------------- //
// --- pipwerks.SCORM.data functions --------------------------------------- //
// ------------------------------------------------------------------------- //


/* -------------------------------------------------------------------------
pipwerks.SCORM.data.get(parameter)
Requests information from the LMS.

Parameter: parameter (string, name of the SCORM data model element)
Returns:   string (the value of the specified data model element)
---------------------------------------------------------------------------- */
convertDataName = function(elName) {
	// converts from Scorm 2004 data element to Scorm 1.2
	// NB: One-way only: doesn't go from 1.2 to 2004
	// NB2: only the elements we're actually using are included here: may need to add more
	var	scorm = pipwerks.SCORM
	if (scorm.version=="2004") {
		return elName
	}
	var arr = elName.split(".")
	if (arr[1]=="interactions") {
		switch(arr[3]) {
			case "learner_response": return "cmi.interactions." + arr[2] + ".student_response";
			case "description": return null;
		}
		return elName
	}
	switch(elName) {
		case "cmi.completion_status": return "cmi.core.lesson_status";
		case "cmi.success_status": return null;
		case "cmi.exit": return "cmi.core.exit";
		case "cmi.learner_name": return "cmi.core.student_name";
		case "cmi.score.scaled": return null;
		case "cmi.score.raw": return "cmi.core.score.raw";
		case "cmi.score.min": return "cmi.core.score.min";
		case "cmi.score.max": return "cmi.core.score.max";
		case "cmi.session_time": return "cmi.core.session_time";
		case "cmi.success_status": return "cmi.core.lesson_status";
		case "cmi.total_time": return "cmi.core.total_time";
	}
	return elName
}
pipwerks.SCORM.data.get = function(parameter){

	parameter = convertDataName(parameter);
	if (parameter == null) {return null};
	var value = null,
	scorm = pipwerks.SCORM,
	trace = pipwerks.UTILS.trace,
	debug = pipwerks.SCORM.debug,
	traceMsgPrefix = "SCORM.data.get(" +parameter +") ";
	if(scorm.connection.isActive){

		var API = scorm.API.getHandle(),
		errorCode = 0;

		if(API){

			switch(scorm.version){
				case "1.2" : value = API.LMSGetValue(parameter); break;
				case "2004": value = API.GetValue(parameter); break;
			}

			errorCode = debug.getCode();

			//GetValue returns an empty string on errors
			//Double-check errorCode to make sure empty string
			//is really an error and not field value
			if(value !== "" && errorCode === 0){

				switch(parameter){

					case "cmi.core.lesson_status":
					case "cmi.completion_status" : scorm.data.completionStatus = value; break;

					case "cmi.core.exit":
					case "cmi.exit" 	: scorm.data.exitStatus = value; break;

				}

			} else {

				trace(traceMsgPrefix +"failed. \nError code: " +errorCode +"\nError info: " +debug.getInfo(errorCode));

			}

		} else {

			trace(traceMsgPrefix +"failed: API is null.");

		}

	} else {

		trace(traceMsgPrefix +"failed: API connection is inactive.");

	}

	trace(traceMsgPrefix +" value: " +value);

	return String(value);

};


/* -------------------------------------------------------------------------
pipwerks.SCORM.data.set()
Tells the LMS to assign the value to the named data model element.
Also stores the SCO's completion status in a variable named
pipwerks.SCORM.data.completionStatus. This variable is checked whenever
pipwerks.SCORM.connection.terminate() is invoked.

Parameters: parameter (string). The data model element
value (string). The value for the data model element
Returns:    Boolean
---------------------------------------------------------------------------- */

pipwerks.SCORM.data.set = function(parameter, value){

	parameter = convertDataName(parameter);
	if (parameter == null) {return false};
	var success = false,res=null,
	scorm = pipwerks.SCORM,
	trace = pipwerks.UTILS.trace,
	makeBoolean = pipwerks.UTILS.StringToBoolean,
	debug = pipwerks.SCORM.debug,
	traceMsgPrefix = "SCORM.data.set(" + parameter + ", " + value + ") ";


	if(scorm.connection.isActive){

		var API = scorm.API.getHandle(),
		errorCode = 0;

		if(API){
			// check for "incorrect" in interactions.result, change to "wrong" in Scorm 1.2

			switch(scorm.version){
				case "1.2" :
				if (value=="incorrect") {
					if (parameter.split(".")[3]=="result") {
						value = "wrong"
					}
				}
				res = API.LMSSetValue(parameter, value);
				break;
				case "2004":
				res = API.SetValue(parameter, value);
				break;
			}
			success =makeBoolean(res)
			if(success){

				if(parameter === "cmi.core.lesson_status" || parameter === "cmi.completion_status"){

					scorm.data.completionStatus = value;

				}

			} else {

				errorCode = debug.getCode();
				trace(traceMsgPrefix +"failed (" + res + "). \nError code: " +errorCode +". \nError info: " +debug.getInfo(errorCode));

			}

		} else {

			trace(traceMsgPrefix +"failed: API is null.");

		}

	} else {

		trace(traceMsgPrefix +"failed: API connection is inactive.");

	}

	return success;

};


/* -------------------------------------------------------------------------
pipwerks.SCORM.data.save()
Instructs the LMS to persist all data to this point in the session

Parameters: None
Returns:    Boolean
---------------------------------------------------------------------------- */

pipwerks.SCORM.data.save = function(){

	var success = false,
	scorm = pipwerks.SCORM,
	trace = pipwerks.UTILS.trace,
	makeBoolean = pipwerks.UTILS.StringToBoolean,
	traceMsgPrefix = "SCORM.data.save failed";


	if(scorm.connection.isActive){

		var API = scorm.API.getHandle();

		if(API){

			switch(scorm.version){
				case "1.2" : success = makeBoolean(API.LMSCommit("")); break;
				case "2004": success = makeBoolean(API.Commit("")); break;
			}

		} else {

			trace(traceMsgPrefix +": API is null.");

		}

	} else {

		trace(traceMsgPrefix +": API connection is inactive.");

	}

	return success;

};


pipwerks.SCORM.status = function (action, status){

	var success = false,
	scorm = pipwerks.SCORM,
	trace = pipwerks.UTILS.trace,
	traceMsgPrefix = "SCORM.getStatus failed",
	cmi = "";
	trace("CompletionStatus: " + action + "; " + status)
	if(action !== null){

		switch(scorm.version){
			case "1.2" : cmi = "cmi.core.lesson_status"; break;
			case "2004": cmi = "cmi.completion_status"; break;
		}

		switch(action){

			case "get": success = pipwerks.SCORM.data.get(cmi); break;

			case "set": if(status !== null){

				success = pipwerks.SCORM.data.set(cmi, status);

			} else {

				success = false;
				trace(traceMsgPrefix +": status was not specified.");

			}

			break;

			default	  : success = false;
			trace(traceMsgPrefix +": no valid action was specified.");

		}

	} else {

		trace(traceMsgPrefix +": action was not specified.");

	}

	return success;

};


// ------------------------------------------------------------------------- //
// --- pipwerks.SCORM.debug functions -------------------------------------- //
// ------------------------------------------------------------------------- //


/* -------------------------------------------------------------------------
pipwerks.SCORM.debug.getCode
Requests the error code for the current error state from the LMS

Parameters: None
Returns:    Integer (the last error code).
---------------------------------------------------------------------------- */

pipwerks.SCORM.debug.getCode = function(){

	var API = pipwerks.SCORM.API.getHandle(),
	scorm = pipwerks.SCORM,
	trace = pipwerks.UTILS.trace,
	code = 0;

	if(API){

		switch(scorm.version){
			case "1.2" : code = parseInt(API.LMSGetLastError(), 10); break;
			case "2004": code = parseInt(API.GetLastError(), 10); break;
		}

	} else {

		trace("SCORM.debug.getCode failed: API is null.");

	}

	return code;

};


/* -------------------------------------------------------------------------
pipwerks.SCORM.debug.getInfo()
"Used by a SCO to request the textual description for the error code
specified by the value of [errorCode]."

Parameters: errorCode (integer).
Returns:    String.
----------------------------------------------------------------------------- */

pipwerks.SCORM.debug.getInfo = function(errorCode){

	var API = pipwerks.SCORM.API.getHandle(),
	scorm = pipwerks.SCORM,
	trace = pipwerks.UTILS.trace,
	result = "";


	if(API){

		switch(scorm.version){
			case "1.2" : result = API.LMSGetErrorString(errorCode.toString()); break;
			case "2004": result = API.GetErrorString(errorCode.toString()); break;
		}

	} else {

		trace("SCORM.debug.getInfo failed: API is null.");

	}

	return String(result);

};


/* -------------------------------------------------------------------------
pipwerks.SCORM.debug.getDiagnosticInfo
"Exists for LMS specific use. It allows the LMS to define additional
diagnostic information through the API Instance."

Parameters: errorCode (integer).
Returns:    String (Additional diagnostic information about the given error code).
---------------------------------------------------------------------------- */

pipwerks.SCORM.debug.getDiagnosticInfo = function(errorCode){

	var API = pipwerks.SCORM.API.getHandle(),
	scorm = pipwerks.SCORM,
	trace = pipwerks.UTILS.trace,
	result = "";

	if(API){

		switch(scorm.version){
			case "1.2" : result = API.LMSGetDiagnostic(errorCode); break;
			case "2004": result = API.GetDiagnostic(errorCode); break;
		}

	} else {

		trace("SCORM.debug.getDiagnosticInfo failed: API is null.");

	}

	return String(result);

};


// ------------------------------------------------------------------------- //
// --- Shortcuts! ---------------------------------------------------------- //
// ------------------------------------------------------------------------- //

// Because nobody likes typing verbose code.

SCORMinit = pipwerks.SCORM.connection.initialize;
SCORMget  = pipwerks.SCORM.data.get;
SCORMset =  pipwerks.SCORM.data.set;
SCORMsave = pipwerks.SCORM.data.save;
SCORMquit = pipwerks.SCORM.connection.terminate;


// ------------------------------------------------------------------------- //
// --- pipwerks.UTILS functions -------------------------------------------- //
// ------------------------------------------------------------------------- //


/* -------------------------------------------------------------------------
pipwerks.UTILS.StringToBoolean()
Converts 'boolean strings' into actual valid booleans.

(Most values returned from the API are the strings "true" and "false".)

Parameters: String
Returns:    Boolean
---------------------------------------------------------------------------- */

pipwerks.UTILS.StringToBoolean = function(string){
	switch(string.toLowerCase()) {
		case "true": case "yes": case "1": return true;
		case "false": case "no": case "0": case null: return false;
		default: return Boolean(string);
	}
};



/* -------------------------------------------------------------------------
pipwerks.UTILS.trace()
Displays error messages when in debug mode.

Parameters: msg (string)
Return:     None
---------------------------------------------------------------------------- */

pipwerks.UTILS.trace = function(msg){

	if(pipwerks.debug.isActive){

		//Firefox users can use the 'Firebug' extension's console.
		// In IE, Firebug lite: <script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>
		if(window.console && window.console.firebug){
			console.log(msg);
		} else if (window.console!=null) {
			window.console.log(msg)
		} else {
			//alert(msg);
		}

	}
};
