
function getBrand() {
	return "default";
}

/**--------------------------------------------------------------------
 * BROWSER DETECTION
 *--------------------------------------------------------------------*/
/** Whether Google Chrome is the Browser */	
function isGoogleChrome() {
	return navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
}

/**--------------------------------------------------------------------
 * QUERY STRING PARSING/PROCESSING
 *--------------------------------------------------------------------*/
var qsParams = null;
/** Parse the Query String */
function parseQueryString() {
	qsParams = new Array();
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0, pos);
			var val = parms[i].substring(pos + 1);
			qsParams[key] = val;
		}
	}
}
/** Get the Parameter. Also initializes Query String array if not available */
function getQSParam($key) {
	if(qsParams == null) {
		parseQueryString();
	}
	return qsParams[$key];
}

/**--------------------------------------------------------------------
 * STARTING FRESH
 *--------------------------------------------------------------------*/
function startFresh() {
	$("#playerContent").empty();
	$("#flashContent").empty();
}

/**--------------------------------------------------------------------
 * OTHER
 *--------------------------------------------------------------------*/
/** Returns true if it is indeed an object tag */
function isObject(targetID){
	var isFound = false;
	var el = document.getElementById(targetID);	
	if(el && (el.nodeName === "OBJECT" || el.nodeName === "EMBED")){
		isFound = true;		
	}
	return isFound;
}
function drawContentOnTop() {
	//var el = document.getElementById("contentContainer");	
	//el.style.zIndex =	2;		
	
	$('#contentContainer').css( 'z-index', 2000);
	$('#contentContainer').css( 'zIndex', 2000);
	
}
function drawContentOnBottom() {
	//var el = document.getElementById("contentContainer");	
	//el.style.zIndex =	-1;		
	
	$('#contentContainer').css( 'z-index', -1000);
	$('#contentContainer').css( 'zIndex', -1000);
}	
function redrawContent($x, $y, $width, $height) {
	//alert("$x: " + $x + ", $y: " + $y + ", $width: " + $width + ", $height: " + $height);
	var el = document.getElementById("contentContainer");	
	el.width = $width;
	el.height = $height;
	//el.style.zIndex =	2;
	
	$('#contentContainer').css( 'z-index', 2000);
	$('#contentContainer').css( 'zIndex', 2000);
	el.style.left = $x + "px"; 
	el.style.top  = $y + "px"; 
	el.style.height   = $height + "px"; 
	el.style.width    = $width + "px"; 
}
/** Replaces a SWF with an empty div */
function replaceSwfWithEmptyDiv(targetID){
	var el = document.getElementById(targetID);
	if(el){		
		var div = document.createElement("div");
			el.parentNode.insertBefore(div, el);
		
		//Remove the SWF
		swfobject.removeSWF(targetID);
	
		//Give the new DIV the old element's ID
		div.setAttribute("id", targetID);
	}
}
function removeSWFDiv(targetID) {
	var el = document.getElementById(targetID);
	if(el){		
		swfobject.removeSWF(targetID);
	}
}
function loadContentSWF($url, $user, $guid){
	//replace object/element with a new div
	if(isObject("flashContent")){
		//replace object/element with a new div
		replaceSwfWithEmptyDiv("flashContent");
	}
	//Embed SWF
	if (swfobject.hasFlashPlayerVersion("9")) {
		//alert("they have it");
		//var attributes = { data: $url, width: "980", height: "370"};
		var attributes = { data: "LCContent.swf", width: "980", height: "370"};
		//, width:"980", height:"497" }
		var params = {};
			params.quality = "high";
			params.name = "Captivate";
			params.wmode = "opaque";
			//params.wmode = "transparent";
			params.bgcolor = "#FFFFFF";
			
			params.menu = "false";
			//alert("loading content swf");
			try {
				params.flashvars = "user=" + user + "&preload=" + $url + "&guid=" + $guid + "&preloader=" + getBrand();
				//alert("flashvars: " + params.flashvars);
			} catch (error) {				
				//User was null
				//alert("There was an error" + user + "," + $url + ": " + $guid);
				params.flashvars = "user=" + "12345" + "&preload=" + $url + "&guid=" + $guid + "&preloader=" + getBrand();
			}
		var obj = swfobject.createSWF(attributes, params, "flashContent");
	} else {
		//alert("they DO NOT have it");
	}
	//TODO: Check to see if Google Chrome still requires drawContentOnBottom() before drawContentOnTop()
	drawContentOnBottom();
	drawContentOnTop();

}
/** Sets the focus to the content */	
function setFocusToContent() {
	var el = document.getElementById("flashContent");
	//el.focus();//DONT DO THIS
}
	
/** Closes the SWF */
function closeSWF() {
	//This closes the SWF
	replaceSwfWithEmptyDiv("flashContent");
	drawContentOnBottom();
}
/** Load the Player SWF */
function loadSWF(url, targetID, user, token){
	//Check for existing SWF
	if(isObject(targetID)){
		//replace object/element with a new div
		replaceSwfWithEmptyDiv(targetID);
	}

	//Embed SWF
	if (swfobject.hasFlashPlayerVersion("9")) {
		//alert("they have it");
		var attributes = { data: url, width: 990, height: 585};
		//default, aaa, ama, ids
		var params = {};
			params.quality = "high";
			params.name = "Captivate";
			//params.wmode = "window";
			params.wmode = "opaque";
			//params.wmode = "transparent";
			params.bgcolor = "#FFFFFF";
			params.menu = "false";
			
			
			//Look for an alternate configuration file other than course.xml
			var hasAlternateConfigFile = false;
			var alternateConfigFile = "";
			try {
				if(getQSParam("configFile") != null) {
					hasAlternateConfigFile = true;
					alternateConfigFile = getQSParam("configFile");
				}
			} catch (error) {
				
			}
			try {
				if(getQSParam("mode") != null) {
					if(getQSParam("mode") == 3) {
						hasAlternateConfigFile = true;
						alternateConfigFile = "free";
					}
				}
			} catch (error) {
				
			}
			
			try {
				params.flashvars = "user=" + user + "&preloader=" + getBrand() +"&wst=" + token + "&isGoogleChrome=" + isGoogleChrome() + "&playerWidth=990&playerHeight=585";
				if(hasAlternateConfigFile) {
					params.flashvars += "&configFile=" + alternateConfigFile;
				}
			} catch (error) {				
				//User was null
				//alert("user was null");
			}
		//alert("before create swf");
		var obj = swfobject.createSWF(attributes, params, targetID);
		//alert("after create swf");
	} else {
		//alert("they DO NOT have it");
	}
}
/** Redirect to the shutdown page */
function shutdown() {
	window.location = "player_shutdown.html";
}
/* Call a function registered as callPlayBall in the SWF named myMovie. */
function getActiveDownloadName() {
	try {
		var activeDownloadName = getMovieName("coursePreloader").getActiveDownloadName();
		return activeDownloadName;
	} catch (error) {
		//SWF does not yet exist on the stage...
		//alert("active download name: " + activeDownloadName;
		//alert("An error occured.  CoursePreloader does likely not yet exist");
	}
	return "";
}
function skipActiveDownload() {
	try {
		getMovieName("coursePreloader").skipActiveDownload();
	} catch (error) {
		//SWF does not yet exist on the stage...
		//alert("active download name: " + activeDownloadName;
		//alert("An error occured.  CoursePreloader does likely not yet exist");
	}
}
/* This utility function resolves the string movieName to a Flash object reference based on browser type. */
function getMovieName(movieName) {
	if (navigator.appName.indexOf("Microsoft") != -1) {
		return window[movieName]
	} else {
		return document[movieName]
	}
}

/** Reloads the SWF */
function reloadSWF() {
	//var path="reloadPage.swf";
	loadSWF(path, 'flashContent');
}
/** Opens up a popup */
function openPopup($url, $name, $w, $h) {
	var newWindow = window.open($url, $name, 'height=' + $h + ',width=' + $w + ',resizable=1, status=0' );
	if (window.focus) {
		newWindow.focus()
	}
	return false;

}