/*Rich Media JavaScript: 
Browser Related Routines

Version: 06.15.10 - vs
Edited: 10.15.10 - vs - retooled completely. Should be final version.
Edited: 11.01.10 - added resetStream(); for retarting AKAMAI streams in the CTAs (I lol at the above comment.)
Edited: 11.04.10 - adjusting mobile detection for run better videos to detect EPX pages with CTAs
Edited: 12.01.10 - 2 - fixed the link for the Run Better videos mobile detection (removed -video form the file name)
Edited: 12.13.10 - added media/community/ folder for mobile video location detection.

*/
			

var mp_tLayer;
var mp_bLayer;
var movieTotalTime;
var swfRandomID;
var experience = false;
var UP_width;
var UP_height;
var UP_location;
var UP_options;
var UP_chaptering = false;
var replacementHTML = "";


function open3pflashlayer(layerID, width, height, func) {
	www = width;
	hhh = height;
	aFunc = func;
	
	dString = arguments[4];
	
	showBlackOverlay("makeFlashUP('" + layerID + "')", "blackDivClicked();");
}

function close3pflashlayer() {
	blackDivClicked();
}

function makeFlashUP(layerID) {
		makeUniversalPlayerDiv('placeFlashUPcode("' + layerID + '")', dString);
}

function placeFlashUPcode(layerID) {
	
	$("#up_main").css({'float' : 'left', 'width' : www + 'px'});
	$("#up_main").css({"height" : hhh + "px"});
	
	if (replacementHTML == "") {
		//If we've stored it already, we don't need it (we can't get it since it's REMOVED from the main page.)
		replacementHTML = $("#" + layerID).html();
	} 
	$("#" + layerID).remove();
	$('#up_main').html(replacementHTML);
	
	centerDiv('UPcontainer'); 
	
	//Activate their flash?
	eval(aFunc + "()");
}



//Required for JS calls to control the player...
function mediaPlayerRemoteCall(movieName, callType, rangeStart, rangeEnd) {
	if (callType == "playpause") {
		getSWF(movieName).mediaPlayerRemoteCall(callType, "", "");
	} else if (callType == "setRange") {
		getSWF(movieName).mediaPlayerRemoteCall(callType, rangeStart, rangeEnd);
	} else if (callType == "seekTo") {
		getSWF(movieName).mediaPlayerRemoteCall(callType, rangeStart, "");
	} else {
		//Do nothing, improper JS call...
	}
}


function setMovieTotalTime(theTime) {
	movieTotalTime = theTime;
	//alert("Movie's Total Time Set To: " + movieTotalTime);
}

function getMovieTotalTime() {
	return(movieTotalTime);
}


function noFlicker(layerName) {
	tempLayer = getLayer(layerName);
	tempLayer.setAttribute("class", "mediaPlayer_invisible");
	tempLayer.className = "mediaPlayer_invisible";
}


function embedUniversalPlayer() {
	//alert('embededUniversalPlayer fired');
	isDemos = demosInPath(window.location.pathname);
	
	//Check For Mobile Device
	doMobile = false;
	doPad = false;
	//|| parsedParm['rm_iPhoneToggle'] == 'true' //Seems to be erroring. Shouldn't be passed this way, anyway.
	if (isiPhone || isAndroid || isPalm || qsParm['rm_iPhoneToggle'] == 'true') {
		doMobile = true;	
	}

	if (isiPad || qsParm['rm_iPadToggle'] == 'true') {
		//alert('iPad Detected');
		doPad = true;	
	}
		
	if (qsParm['rm_autoLaunch'] != 'true' && !doMobile) {
		//Do it normally:
		if (doPad) {
			//Being embeded on the site somewhere 
			embedMobile.apply(this, arguments);
		} else {
			mediaPlayerBuilder2.apply(this, arguments);
		}
		//should it be this sometimes?
		//openMediaPlayer2.apply(this, arguments);

	} else {
		if (isDemos) {
			//Not auto lauching and on a /demos landing page;
			adjustMPlandingPage.apply(this, arguments);
		} else {
			//Being embeded on the site somewhere.
			if (!doMobile && !doPad) {
				//alert('PC only');
				mediaPlayerBuilder2.apply(this, arguments);
			} else {
				embedMobile.apply(this, arguments);
			}
		}
	}
}


var mediaPlayerBuilder2 = function () {

		topLayerTP = arguments[0];
		flashLayer = arguments[1];
		flashObjectName = arguments[2];
		flashDataDiv = arguments[3];
		swfWidth = arguments[4];
		swfHeight = arguments[5];
		dataLocation = arguments[6];
		
		theOptions = arguments[7];
		
		//Parse Options:
		var parsedOpts = new Array();
	
		var params = theOptions.split(',');
		for (var i=0; i<params.length; i++) {
			var pos = params[i].indexOf('=');
			if (pos > 0) {
				var key = params[i].substring(0,pos);
				var val = params[i].substring(pos+1);
				parsedOpts[key] = val;
			}
		}
		
		
		
		
		pauseAtStart = parsedOpts['pausedAtStart'];
		pauseImage = parsedOpts['pauseImage'];
		pType = parsedOpts['dhtml'];
		seekTo = parsedOpts['seekTo'];
		markRange = parsedOpts['markRange'];
		chaptering = parsedOpts['chaptering'];
		configFile = parsedOpts['cfig'];
		skinColor = parsedOpts['skinColor'];
		ctaURL = parsedOpts['ctaURL'];
		ctaImage = parsedOpts['ctaImage'];
		isSapphire = parsedOpts['isSapphire'];
		
		swfRandomID = Math.floor(Math.random()*900001);
		

		if (pType != "true" && $('#description').length > 0) {
			
			//Get the left side description data
			var newlefthtml = "";
			if (getLayer("description")) {
				
				var leftdesc = ie ? getLayer("description").firstChild.firstChild : getLayer("description").firstChild.nextSibling.firstChild;
				var showDesc = getLayer("description").attributes["exists"].value;
			}
			
			
			for(e = leftdesc; e != null; e = e.nextSibling) {
				var attrs = e.attributes;
				if(attrs != null) {
					var eid = attrs["id"].value;
					if((eid != null) && ((eid == "text") || (eid == "logoImage"))) {
						//alert(eid);
						//alert(e.firstChild.attributes["src"].value);
						//alert(e.innerHTML);
						if (eid == 'logoImage') {
							if (e.firstChild.attributes["src"].value != '/global/images/spacer.gif') {
								newlefthtml += '<div class="rm_textDisplay">' + e.innerHTML + '</div>';
							}
						} else {
							newlefthtml += '<div class="rm_textDisplay">' + e.innerHTML + '</div>';
						}
					}
				}
			}
		}
		
	
		
		swfName = "/global/swf/sapMediaPlayer_V2.swf";
		//This prevents the weird IE not reloading the swf and making external interface die.
		swfName += "?rdm=" + Math.random()*9999; //Attempting to prevent the same SWF from loading
		
		playerType = "inLine";
		theXHTMLloc = dataLocation;
		
		ps = "false";
		if (pauseAtStart) {
			if (pauseAtStart == "true") {
				ps = "true";
			}
		}
		
		pi = null;
		if (pauseImage) {
			if (pauseImage != null) {
				pi = pauseImage;
			}
		}
		
		theDHTML = "false";
		videoWidth = swfWidth;
		videoHeight = swfHeight;
		if (pType) {
			if (pType == "true") {
				theDHTML = "true";	
				videoWidth -= 32;
				videoHeight -= 32;
			} 
		}
		
		
		
		//Check For Config Override File:
		cURLvar = null;
		if (configFile) {
			cURLvar = configFile;
		}
		checkForConfig = qsParm['cfig'];
		if (checkForConfig) {
			cURLvar = qsParm['cfig'];
		}	
		
		
		
		var flashvars = {
			coName: playerType,
			dhtml: theDHTML,
			flashObjectName: flashObjectName,
			swfRandomID: swfRandomID,
			videoWidth: videoWidth,
			videoHeight: videoHeight,
			theXHTMLloc: theXHTMLloc,
			flashDataDiv: flashDataDiv,
			pauseAtStart: ps,
			pauseImage: pi,
			cURL: cURLvar
		};
		
		
		if (!seekTo) {
			//If not defined in function, check query String...
			seekTo = qsParm['seekTo'];
		}
		if (seekTo) {
			flashvars.seekTo = "true";
			flashvars.seekRangeStart = seekTo;
		}
		
		if (skinColor) {
			flashvars.skinColor = skinColor;
		} 
		checkSkin = qsParm['skinColor'];
		if (checkSkin) {
			flashvars.skinColor = qsParm['skinColor'];
		}	
		
		//&markRange=00:30-00:60
		if (!markRange) {
			//If not defined in function, check query String...
			markRange = qsParm['markRange'];
		}
		
		if (markRange) {
			theRange = markRange.split('-');
			flashvars.markRange = "true";
			flashvars.rangeStart = theRange[0];
			flashvars.rangeEnd = theRange[1];
		}
		
		//Check for paused at start in URL:
		if (qsParm['pausedAtStart'] == 'true' && theDHTML != 'true') {
			flashvars.pauseAtStart = "true";
		}

		//Check for ctaURL in the string:
		if (ctaURL) {
			//alert('ctaURL: ' + ctaURL);	
			//alert('ctaImage: ' + ctaImage);
			flashvars.z_ctaURL = ctaURL;
			flashvars.z_ctaImage = ctaImage;
		}
		
		if (isSapphire) {
			flashvars.isSapphire = "true";	
		}
		
		//allowScriptAccess: "sameDomain"
		
		var params = {
		  swfLiveconnect: "true",
		  wmode: "transparent",
		  allowFullScreen: "true",
		  allowScriptAccess: "always"
		};
		var attributes = {
		  id: flashObjectName,
		  name: flashObjectName
		};
		
		//if isiPad then use QT version!?
		if (isiPad || qsParm['rm_iPadToggle'] == 'true') {
			pageURL = window.location.pathname
			mPath = getMobileVideoPath(pageURL);
			pPath = getProxyPath(mPath);
		
			fileExists = checkIfFileExists(pPath, 'placeQTMovie()', 'placeNoMovie_X()');
			
		} else {
			
			//alert('vs: ' + flashvars.pauseAtStart + ' - ' + flashvars.pauseImage);
			
			swfobject.embedSWF(swfName, flashLayer, swfWidth, swfHeight, "9.0.115", "expressInstall.swf", flashvars, params, attributes);	
	
			var anc = getLayer(topLayerTP);
			if(anc != null)
			{
				var swf = getLayer(flashLayer);
				if(swf != null)
				{
					//FLash Exists. Display the Content.
					swf.className = "div.visible";
		
				} else {
					//No flashSpace Div...
				}
			} else {
				//No FlashContent Div...
		}
		}


		if (getLayer("description") && pType != "true" && showDesc == "true" ) { //getLayer("description") && pType != "true" && showDesc == "true"
			//insert the description to the left of the media player
			//alert('need to add left text layer');
			var leftelem = getLayer("mediaLeftText");
			leftelem.innerHTML = newlefthtml;
			
			//IE 6 Fix for layers splitting down...
			$('#mediaLeftText').css("width",145);
		}
				
		
		if (chaptering == "true") {
			swfName = "/global/swf/sapMP_ChapteringMenu.swf";
			flashObjectName = 'chapteringSWF';
			if (experience) {
				flashLayer = "chapteringDiv";
			} else {
				flashLayer = "mediaLeftText";
			}
			
			
			//cswfWidth = 145; //158 - original size
			//cswfHeight = 284; //284 - original size

			
			cswfHeight = swfHeight; // Match the height of the height of the SWF too

			if (experience) {
				cswfWidth = 978 - swfWidth - 10; 
				cswfHeight -= 20; // remove 20 px for the DHTML border
			} else {
				cswfWidth = 670 - swfWidth; //670 is the space available, minus the width of the SWF
			}
			
			if ((BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6)) {		
				//for IE 6 it needs to be smaller? - CSS borders I think...
				cswfWidth -= 100;
			}
			
			//This is mostly for the 3rd party player. (The cswfWidth will be a negative number)
			if (cswfWidth < 0) {
				var bWidth = browserWindowSize()[0]; //BrowserWindowWidth...
				if (bWidth < 950) {
					cswfWidth = bWidth - swfWidth - 10;
				} else {
					cswfWidth = 230;
				}

			}

			if (!experience) {
				$('#mediaLeftText').css("width",cswfWidth);
			}
			
			var flashvars = {
				dhtml: theDHTML,
				flashObjectName: flashObjectName,
				theXHTMLloc: theXHTMLloc,
				flashDataDiv: flashDataDiv,
				swfRandomID: swfRandomID
			};
			
			
			if (experience) {
				flashvars.playerObjectName = 'rmDHTMLplayer';
			}
			
			var params = {
			  swfLiveconnect: "true",
			  wmode: "transparent",
			  allowFullScreen: "true",
			  allowScriptAccess: "always"
			};
			var attributes = {
			  id: flashObjectName,
			  name: flashObjectName
			};

			swfobject.embedSWF(swfName, flashLayer, cswfWidth, cswfHeight, "9.0.115", "expressInstall.swf", flashvars, params, attributes);
		}
		
		if(parsedOpts['wsdlToggle']) {
			if (parsedOpts['wsdlToggle'] == "true") {
				makeAMovies(16);	
			}
		}

}



function placeQTMovie() {
	movSRC = mPath;
	movHeight = swfHeight;
	movWidth = swfWidth;
	
	qt_html = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='qtplugin.cab' height='" + movHeight + "' width='" + movWidth + "'><embed src='" + movSRC + "' autoplay='true' height='" + movHeight + "' width='" + movWidth + "' scale='tofit' type='video/quicktime' pluginspage='download' /></object>";
	
	$('#' + flashLayer).html(qt_html);
	
	//Must Make the layer Visible
	var swf = getLayer(flashLayer);
	swf.className = "div.visible";
}

// 09/23/10 - this function exists in rm_dhtml.js
//Renamed with _X to prevent errors - might be able to be removed.
//Vince
function placeNoMovie_X() {
	no_qt_html = "<p>we are sorry. The video you've requested is has not been coverted for mobile devices.</p>"
	
	$('#' + flashLayer).html(no_qt_html);
	
	//Must Make the layer Visible
	var swf = getLayer(flashLayer);
	swf.className = "div.visible";
}



function openMediaPlayer2(dataLocation, mediaType, parameters) {
	var parsedParm = parseString(parameters);
		
	optionOne = "";
	optionTwo = "";
	optionThree = "";
	
	if (mediaType == "newWin_XML") {
		//Open New Window and load XML
		
		optionOne += '/demos/mmov/mediaPlayerMaster_01.html?xml_Location=' + dataLocation + '&swf_height=' + parsedParm['height'] + '&swf_width=' + parsedParm['width'];
		
		
		optionTwo += "mediaPlayerWindow";
		
		optionThree += "width=" + parsedParm['width'] + ",height=" + parsedParm['height'];

		//Seek To Options
		if (parsedParm['seekTo']) {
			optionOne += "&seekTo=" + parsedParm['seekTo'];
		}
		
		//Mark Range Options
		if (parsedParm['markRange']) {
			optionOne += "&markRange=" + parsedParm['markRange'];
		}
		
		//Pop Open the Window:
		window.open(optionOne, optionTwo, optionThree);
		
	} else if (mediaType == "dhtml_XML") {
		
		playerType = "demoTemp"; 
		
		swfWidth = parseInt(parsedParm['width']) + 32; //16 pixel border 'round the edge...
		swfHeight = parseInt(parsedParm['height']) + 32;
		
		pathToSwf = "/"; //Mark for V2
		originalPath = ""; //V2 does not need orginal paths... all paths should be 'root absolute'.
		
		//Write the DHTML Layer:
		writeDHTMLlayer2(dataLocation, playerType, swfWidth, swfHeight, pathToSwf, originalPath);
		
		
		
		
	} else if (mediaType == "newWin_XHTML") {
				
		flashDataDiv = parsedParm['flashDataDiv'];
		
		optionOne += '/demos/mmov/mediaPlayerMaster_01.html?theXHTMLloc=' + dataLocation + '&flashDataDiv=' + flashDataDiv + '&swf_height=' + parsedParm['height'] + '&swf_width=' + parsedParm['width'];
		
		optionTwo += "mediaPlayerWindow";
		
		optionThree += "width=" + parsedParm['width'] + ",height=" + parsedParm['height'];

		//Seek To Options
		if (parsedParm['seekTo']) {
			optionOne += "&seekTo=" + parsedParm['seekTo'];
		}
		
		//Mark Range Options
		if (parsedParm['markRange']) {
			optionOne += "&markRange=" + parsedParm['markRange'];
		}
		
		//Pop Open the Window:
		window.open(optionOne, optionTwo, optionThree);

	} else if (mediaType == "dhtml_XHTML" || mediaType == "sapphire10") {
		
		experience = true;
		playerType = "demoTemp"; 
		flashDataDiv = parsedParm['flashDataDiv'];
		
		tempWidth = (parsedParm['width'] != undefined) ? parsedParm['width'] : parsedParm['rmWidth'];
		tempHeight = (parsedParm['height'] != undefined) ? parsedParm['height'] : parsedParm['rmHeight'];
		
		layerWidthINT = parseInt(tempWidth) + 32; //16 pixel border 'round the edge...
		layerHeightINT = parseInt(tempHeight) + 32;
		
		swfWidth = parseInt(tempWidth);
		swfHeight = parseInt(tempHeight);
		
		//Added the tempWidth conditions to find for rmWidth vs. width (06.30.10 - VS);
		
		//layerWidthINT = parseInt(parsedParm['width']) + 32; //16 pixel border 'round the edge...
		//layerHeightINT = parseInt(parsedParm['height']) + 32;
		
		//swfWidth = parseInt(parsedParm['width']);
		//swfHeight = parseInt(parsedParm['height']);
		

		
		//alert(swfWidth);
		
		var extraOptions = "";
		
		if (mediaType == "sapphire10") {
			extraOptions += ",isSapphire=true";
		}
		
		//Seek To Options
		if (parsedParm['seekTo']) {
			extraOptions += ",seekTo=" + parsedParm['seekTo'];
			//alert(parsedParm['seekTo']);
		}
		
		//Mark Range Options
		if (parsedParm['markRange']) {
			extraOptions += ",markRange=" + parsedParm['markRange'];
		}
		
		if (parsedParm['chaptering']) {
			extraOptions += ",chaptering=" + parsedParm['chaptering'];
			//alert('chaptering=' + parsedParm['chaptering']);	
			UP_chaptering = parsedParm['chaptering'];
		}
		
		if (parsedParm['skinColor']) {
			extraOptions += ",skinColor=" + parsedParm['skinColor'];
		}
		
		if (parsedParm['wsdlToggle']) {
			extraOptions += ",wsdlToggle=" + parsedParm['wsdlToggle'];
		}
		
		if (parsedParm['ctaURL']) {
			extraOptions += ",ctaURL=" + parsedParm['ctaURL'];
			extraOptions += ",ctaImage=" + parsedParm['ctaImage'];
		}
		
		if (parsedParm['pauseImage']) {
			extraOptions += ",pauseImage=" + parsedParm['pauseImage'];
			extraOptions += ",pauseAtStart=true";
		} else {
			extraOptions += ",pauseAtStart=false";
		}
		
		bottomLayerName = 'bottomLayer';
		toplayerName = 'topLayer';
		mediaLayerName = 'mediaPlayerLayer';
		//layerWidthINT = 524;
		//layerHeightINT = 292;
		locationHREF = dataLocation;
		
		
		
		mp_tLayer = toplayerName;
		mp_bLayer = bottomLayerName;
		UP_width = layerWidthINT;
		UP_height = layerHeightINT;
		UP_location = locationHREF;
		var theOptions = "dhtml=true" + extraOptions;
		UP_options = theOptions;
		
		
		
		//This should be event based... but I ain't getting into JS events just yet.
			//for now it's function to function to function.
			
		if (isiPad || qsParm['rm_iPadToggle']) {
			mPath = getMobileVideoPath(locationHREF);
			make_rm_qt(mPath, tempWidth, tempHeight);
		} else if (isiPhone || isAndroid || isPalm || qsParm['rm_iPhoneToggle'] == 'true') {
			//DO nothing. Landing page has the link to launch it...
		} else {
			showBlackOverlay("makeUPdiv('test');", "blackDivClicked();");
		}
		
	} else if (mediaType == "dhtml_PDF") {	
		
		openPDFlayer(dataLocation, parsedParm['width'], parsedParm['height']);
		
	} else {
		
	
	}
	
	
}

function ie6layerFix() {
	if ((BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6)) {		
		//set the layer to absolute for IE6 
		var fLayer = getLayer('dhtmlMediaLayer');
		fLayer.style.position = "absolute";
		
		//Set interval for IE6 to move the layer 
		iemove = window.setInterval(ie6layerMove, 200);
	}		
	
}

function ie6layerMove() {
	var offset = ((392 / 2) + ((browserWindowSize()[1] - 392) / 2)); 
	var fLayer = getLayer('dhtmlMediaLayer');
	fLayer.style.top = (document.documentElement.scrollTop + offset) + 'px';
}




function removeRMplayer() {
	
	getSWF("rmDHTMLplayer").remoteClose(); 
	//removeRMdiv('bottomLayer', 'topLayer', 'mediaPlayerLayer');	
}


function writeDHTMLlayer2(theXMLlocation, playerType, swfWidth, swfHeight, pathToSwf, originalPath) {	
	flashDataDiv = arguments[6]; // optional Paramter
	
	theLayerCode = "";
	swfWidthINT = parseInt(swfWidth);
	swfHeightINT = parseInt(swfHeight);

	//make the DIVs - Layers...
	theLayerCode += '<div id="theDiv" onclick="rm_divClose();" style="cursor: pointer;">&nbsp;</div>';
	
	theLayerCode += '<div id="mp_flashSpace"><div id="mediaPlayerLayer">';
	
	//No Flash Content HTML below...
	theLayerCode += '<table width="' + swfWidthINT + '" border="1" cellpadding="5" bordercolor="#698797" bgcolor="#FFFFFF"><tr><td height="' + swfHeightINT + '" valign="middle">'
	theLayerCode += '<table width="' + (swfWidthINT - 40) + '" border="0" align="center"><tr><td>'
	theLayerCode += '<p class="nf_style2">Missing Or Older Version of Adobe\'s Flash Player Detected</span></p>'
	theLayerCode += '<p><span class="nf_style1">You do not have the Adobe Flash Player needed to view this SAP Video. Please download it by following this <a href="http://get.adobe.com/flashplayer" target="_blank">link</a>.<br/>If you prefer, please follow the links on this page to save this SAP Video in the format of your choice. </span> </p>';
	theLayerCode += '<p class="nf_style1"><a href="JavaScript:alloyHide(\'nothing\');">Click here</a> to close this window.</p>'
	theLayerCode += '</td></tr></table>';
	theLayerCode += '</td></tr></table>';
	
	
	theLayerCode += '</div></div>';
	
	//Set the Styles
	theLayerCode += '<style type="text/css">';
	
	theLayerCode +='#theDiv {position:absolute;opacity: .8;-moz-opacity: .8;top: 0px;left: 0px;filter: alpha(opacity=80);height: 100%;width: 100%;background-color: #333333;z-index: 33;visibility: hidden;}';
	theLayerCode += '#mp_flashSpace {position:fixed;top: 50%;left: 50%;margin-top: -' + swfHeightINT/2 + 'px; margin-left: -' + swfWidthINT/2 + 'px;  background-color: #FFFFFF; padding:0px; z-index: 34; visibility: hidden; width:' + swfWidthINT + 'px;}'
	theLayerCode += '#mediaPlayerLayer { width:100%; height:100%;}';
	theLayerCode += '.nf_style1 {font-family: Arial, Helvetica, sans-serif;	font-size: 12px;}';
	theLayerCode += '.nf_style2 {font-family: Arial, Helvetica, sans-serif;	color: #698797;	font-size: 19px; font-style: bold; font-weight: bold;}';
	
	theLayerCode += '</style>';
	
	

	//Below, this doesn't work:
	//document.getElementsByTagName('body').item(0).innerHTML+=theLayerCode;
	
	//This is the proper method to insert the code
	var myElement = document.createElement('div');
	myElement.id = "newMediaPlayerLayer";
	myElement.innerHTML = theLayerCode;
	document.getElementsByTagName('body').item(0).appendChild(myElement);
	
	
	
	//IE Style Fixes
	var fLayer = getLayer('mp_flashSpace');
	
	fLayer.style.left = "50%";
	fLayer.style.marginLeft = "-" + swfWidthINT/2 + "px";
	fLayer.width = swfWidthINT + "px";

	//start the IE 6 fix horizontal scroll.
	ie6layerSet();
		

	//SWF Object 1.5 Embed Code	
	//swfName = "sapMediaPlayer.swf?rdm=" + Math.random()*9999; //Attempting to prevent the same SWF from loading
	if (pathToSwf == "/") {
		swfName = "/global/swf/sapMediaPlayer_V2.swf"
	} else {
		swfName = pathToSwf + "global/swf/sapMediaPlayer.swf"
	}
	//alert("pathToSwf: " + pathToSwf);
	//alert("theXMLlocation: " + theXMLlocation);
	//alert("originalPath: " + originalPath);


	showMediaPlayer();
	
}


function ie6layerSet() {
	//This must be called on Body onLoad...  resets the layer for IE6
	if ((BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6)) {
		//set the layer to absolute for IE6 
		var fLayer = getLayer('mp_flashSpace');
		fLayer.style.position = "absolute";
		
		//Set interval for IE6 to move the layer 
		iemove = window.setInterval(move_box, 200);
	}	
}



function showMediaPlayer() {
	//Show the 2 layers
	hideTheLayer('mp_flashSpace', 'visible');
	hideTheLayer('theDiv', 'visible');
	
	//Set the height of the gray div to the size of the page
	var fLayer = getLayer('theDiv');
	fLayer.style.height = getHeight() + 'px';
	
	if (arguments[0] != true) { // optional Paramter - true/false - "Is not SWF"
		//Start the interval to activate flash
		der = setInterval(rm_playIt, 200);
	}
}

function getHeight() {
	if (BrowserDetect.browser == "Explorer") {
		//alert(document.documentElement.scrollHeight);
		return(document.documentElement.scrollHeight);
	} else {
		return(document.body.scrollHeight);
	}

	//document.documentElement.offsetHeight
	//document.documentElement.scrollHeight
	//document.body.scrollHeight
}
	
	
function rm_playIt(){
	clearInterval(der);
	//Chrome seems to be failing with the call below:
	//The player is usually one of the following. Going to have to make a global var for the name of the SWF object itself.
	var theSWFage;
	theSWFage = getSWF("rmDHTMLplayer");

	if (theSWFage === undefined) {	
		theSWFage = getSWF("sapMediaPlayer");
	}
	
	//If it's still not defined, re make the der interval and try again...
	if (theSWFage === undefined) {
		der = setInterval(rm_playIt, 500);	
	} else {
		try {
			theSWFage.startItUp();
		} catch(err) {
			der = setInterval(rm_playIt, 500);
		}

		 
	}
}

function rm_divClose() {
	//Call the remoteClose ExternalInterface Function in Flash.
	//alert('rm_divClose');
	getSWF("sapMediaPlayer").remoteClose(); 
}


function rm_DivHide(theData) {
	//09.29.10 - cleaned up for stream closing.
	//blackDivClicked();
	
	closeBlackDiv();
	
	//Removed on 06.15.10 - new jQuery DIV code
	/*//used only for the DHTML media layer.	
	hideTheLayer(mp_tLayer, 'hidden');
	hideTheLayer(mp_bLayer, 'hidden');

	//Remove the Interval for IE 6 if it's running.
	if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6) {	
		clearInterval(iemove); //Clear the IE6 Interval
	}
	
	removeRMdiv();*/
}



var inLinePlayerControls = {
	
	init: function () {
		this.isInlinePlaying = false;
		this.playingInlineSWF = "";
	},
	
	setPlaying: function(swfObj) {
		this.isInlinePlaying = true;
		this.playingInlineSWF = swfObj;
		//alert ('setPlaying: ' + swfObj);
	},
	
	setPaused: function(swfObj) {
		this.isInlinePlaying = false;
		this.playingInlineSWF = "";
		//alert ('setPaused: ' + swfObj);
	},
	
	checkAndPause: function(swfObj) {
		if(this.isInlinePlaying == true && this.playingInlineSWF != swfObj) {
			//alert ('this is currnetly playing: ' + this.playingInlineSWF);
			this.pauseSWF(this.playingInlineSWF);
		}
	},
	
	pauseSWF: function(swfObj) {
		//alert('playpause');
		mediaPlayerRemoteCall(swfObj, 'playpause');
	}
}


inLinePlayerControls.init();
//inLinePlayerControls.setPlaying(swfObj)
//inLinePlayerControls.checkAndPause(swfObj)
//inLinePlayerControls.setPaused(swfObj)

var richMediaPlayer = {
	
	makeInline: function () {
		//alert('making inLine');
		//10.05.10
		
	},
	
	
	openExperience: function () {
		mediaSource = arguments[0];
		eType = arguments[1];
		theOptions = arguments[2];
		
		openMediaPlayer2(mediaSource, eType, theOptions);
	}
	
}









function openUniversalPlayer(assetGUID, dataString) {
	
	
	var parsedParm = parseString(dataString);
	
	if (parsedParm['type'] == 'newWindowSWF') {
		
		//Just pop open a window with the SWF at the proper dimensions.
		
		winName = 'oup_window';
		theSize = 'width=' + parsedParm['width'] + ',height=' + parsedParm['height'];
		
		window.open(parsedParm['src'],winName,theSize);	
		
	} else if (parsedParm['type'] == '3pflash') {
		
		dataLayer = assetGUID;
		width = parsedParm['width'];
		height = parsedParm['height'];
		func = parsedParm['func'];
		
		open3pflashlayer(dataLayer, width, height, func, dataString);
		
	} else if (parsedParm['type'] == 'PodCast') {
		
		
		//rm_podCast.js is required on the page for this to work:
		makeUPpodCast('dataDiv', dataString);
		
	} else if (parsedParm['type'] == 'newWindow') {
		
		//loop thru features for the window:
		features = "";
		for (key in parsedParm) {
			 if (key != "windowName" && key != "src" && key != "type") {
				 features += key + "=" + parsedParm[key] + ","; //Add each of the query string parameters (except autoLaunch)
			 }
		}
		features = features.substring(0, features.length - 1); //Remove the last comma
		window.open (parsedParm['src'], parsedParm['windowName'], features); 
		
		
	} else {		
		//Check for mobile device:
		//Make Mobile path:
		mPath = getMobileVideoPath(parsedParm['src']);
			
		//Make proxypath: 
		pPath = getProxyPath(mPath);
		
		if(isiPhone || isAndroid || isPalm || qsParm['rm_iPhoneToggle'] == 'true' || parsedParm['rm_iPhoneToggle'] == 'true') // (isiPhone || isAndroid || isPalm)
		{			
				
			//Check to see if the file exists.
			if (parsedParm['src'] == "run_better_eng" || parsedParm['src'] == "/demos/RichMedia/media/sap-run-better-us.epx") {
				mPath = 'http://download.sap.com/mobile/media/sap-run-better-mob.mp4';	
				fileExists = true;
				getMovie();
			} else if (parsedParm['src'] == "run_better_br" || parsedParm['src'] == "/demos/RichMedia/media/sap-run-better-bz.epx") {
				mPath = 'http://download.sap.com/mobile/media/sap-run-better-bz-pt-mob.mp4';	
				fileExists = true;
				getMovie();
			} else if (parsedParm['src'] == "run_better_de" || parsedParm['src'] == "/demos/RichMedia/media/sap-run-better-de.epx") {
				mPath = 'http://download.sap.com/mobile/media/sap-run-better-de-mob.mp4';	
				fileExists = true;
				getMovie();
			} else {
				fileExists = checkIfFileExists(pPath, 'getMovie()', 'noMobile()');
			}
			
			
		} else if (isiPad || qsParm['rm_iPadToggle'] == 'true' || parsedParm['rm_iPadToggle'] == 'true') //(isiPad)
		{
			//Ipads get Universal Player Experience, but just embeded QT player.			
			qtW = parsedParm['width'];
			qtH = parsedParm['height'];
			wsdlToggle = parsedParm['wsdlToggle'];
			//Check to see if the file exists.
			
			if (parsedParm['src'] == "run_better_eng" || parsedParm['src'] == "/demos/RichMedia/media/sap-run-better-us.epx") {
				mPath = 'http://download.sap.com/mobile/media/sap-run-better-mob.mp4';	
				fileExists = true;
				getQTMovie();
			} else if (parsedParm['src'] == "run_better_br" || parsedParm['src'] == "/demos/RichMedia/media/sap-run-better-bz.epx") {
				mPath = 'http://download.sap.com/mobile/media/sap-run-better-bz-pt-mob.mp4';	
				fileExists = true;
				getQTMovie();
			} else if (parsedParm['src'] == "run_better_de" || parsedParm['src'] == "/demos/RichMedia/media/sap-run-better-de.epx") {
				mPath = 'http://download.sap.com/mobile/media/sap-run-better-de-mob.mp4';	
				fileExists = true;
				getQTMovie();
			} else {
				fileExists = checkIfFileExists(pPath, 'getQTMovie()', 'noMobile()');
			}
		} else {
			//Not a moble device. Open the experience.
			
			if(parsedParm['rm_isMobile'] == 'true') {
				if (isiPhone || isAndroid || isPalm) {
					getMovie();
				} else if (isiPad) {
					qtW = parsedParm['width'];
					qtH = parsedParm['height'];
					getQTMovie();
				} else {
					openExperience(assetGUID, dataString);
				}
			} else {
				openExperience(assetGUID, dataString);
			}
			
		}
	}
}


function getMovie() {
	//alert('getting just the mp4: ' + mPath);
	window.location.href=mPath;
}


function getQTMovie() {
	//alert('make QT layer mp4: ' + mPath);
	make_rm_qt(mPath, qtW, qtH);
}

function noMobile() {
	//alert('no mobile');	
	window.location.href="/demos/rm/rm_nomobile.epx";
}



function openExperience(assetGUID, dataString) {
	var parsedParm = parseString(dataString);
	
	
	var mType;
	if (parsedParm['type'] == "sapphire10") {
		mType = "sapphire10";
	} else {
		mType = "dhtml_XHTML";
	}
	var pm = 'flashDataDiv=' + parsedParm['flashDataDiv'] + ',width=' + parsedParm['width'] + ',height=' + parsedParm['height'];
	
	if (parsedParm['seekTo']) {
		pm+= ',seekTo=' + parsedParm['seekTo'];
	}
	
	if (parsedParm['markRange']) {
		pm+= ',markRange=' + parsedParm['markRange'];
	}
	
	if (parsedParm['chaptering']) {
		pm+= ',chaptering=' + parsedParm['chaptering'];
	}
	
	if (parsedParm['pausedAtStart']) {
		pm+= ',pausedAtStart=' + parsedParm['pausedAtStart'];
	}
	
	if (parsedParm['wsdlToggle']) {
		pm+= ',wsdlToggle=' + parsedParm['wsdlToggle'];
	}
	
	if (parsedParm['ctaURL']) {
		pm+= ',ctaURL=' + parsedParm['ctaURL'];
		
		//If there's a ctaImage, use it:
		if (parsedParm['ctaImage']) {
			pm+= ',ctaImage=' + parsedParm['ctaImage'];
		} else {
			//use the default one:
			pm+= ',ctaImage=/global/images/rm_images/sapphire-cta-02.jpg';
		}
		
		//pm+= ',pausedAtStart=true';
		//pm+= ',pauseImage=/global/images/rm_images/sapphire10_pcta.jpg';
		
	}
	
	if (parsedParm['pauseImage']) {
		pm+= ',pausedAtStart=true';
		pm+= ',pauseImage=' + parsedParm['pauseImage'];
	}
		
	openMediaPlayer2(parsedParm['src'], mType, pm);
}



function getMobileVideoPath(epxPage) {
	//This function converts a epxPage path (string) to it's equivilient download.sap.com/mobile/ path.
	//Reworked: 08.16.10
	//Reworked: 10.05.10 - stripped out http://server/
	
	//alert('getMobileVideoPath: ' + epxPage);
	
	p1 = epxPage.toLowerCase();
	
	//Strip out the http://whatever/ first.
	if (p1.indexOf("http://") >=0) {
		thirdSlash = p1.indexOf("/", 8); // the third / is after the URL - http://www.whatever.com/something/somethingelse
		p1 = p1.substring(thirdSlash);
	}
	if (p1.indexOf("rtmp://") >= 0)
       {thirdSlash = p1.indexOf( "/", 8); // the third / is after the URL - rtmp://www.whatever.com/something/somethingelse
        p1 = p1.substring(thirdSlash);
    }
	
	var u1=p1.match(/[a-zA-Z0-9-]*\./);
	u1 = "" + u1;
	u1 = u1.substring(0, u1.length - 1);
	ext = p1.substring(p1.length - 3);
	//alert('p1:' + p1);
	var sd;
	
	if ((p1.indexOf("richmedia/videos/") || (p1.indexOf("vod/videos/") >= 0)) >= 0) {
		sd = 'videos/';
		ext = 'mp4';
	} else if ((p1.indexOf("richmedia/demos/") || (p1.indexOf("vod/demos/") >= 0)) >= 0) {
		sd = 'demos/';
		ext = 'mp4';
	} else if (p1.indexOf("media/community/") >= 0) {
		//rtmp://cp86361.edgefcs.net/ondemand/vod/media/community/2008_01_09_PMM/2008_01_09_PMM.mp4
		//to
		//http://download.sap.com/mobile/media/community/2008_01_09_PMM/2008_01_09_PMM-mob.mp4
		//media/community/2008_01_09_PMM/2008_01_09_PMM-mob.mp4
		
		rr = p1.lastIndexOf("/"); //Find the last / to get file name
		tt = p1.lastIndexOf("."); //Find the last . to get the extension.
		yy = p1.indexOf("media/community/"); //Find the community folder
		
		u1 = p1.substring(rr + 1, tt);
		ext = p1.substring(tt + 1);
		
		//alert(rr);
		//alert('community - u1: ' + u1);
		sd = p1.substring(yy, rr + 1);
		
	} else if (p1.indexOf("vod/media/") >= 0) {
		sd = 'media/';
		ext = 'mp4';
	} else if ((p1.indexOf("richmedia/podcasts/") >= 0) || (p1.indexOf("mmov/audio/") >= 0)) {
		sd = 'audio/';
		ext = 'mp3';
	} else {
		sd = 'media/';
		ext = 'mp4';
	}

	u1 = 'http://download.sap.com/mobile/' + sd + u1 + '-mob.' + ext;
	//alert('returned getMobileVideoPath: ' + u1);
	return (u1);
	
	//Old Version: 
	//DH - 06.17.10
	/*p1 = epxPage.toLowerCase();
	var u1=p1.match(/[a-zA-Z0-9-]*\./);
	u1 = "" + u1;
	u1 = u1.substring(0, u1.length - 1);
	var sd = p1.indexOf("richmedia/videos/") >= 0 ? "videos/" : "demos/";
	u1 = 'http://download.sap.com/mobile/' + sd + u1 + '-mob.mp4';
	
	return (u1);*/	
}


function getProxyPath(mobilePath) {
	//http://download.sap.com/mobile/demos/sap-crm-deliver-superior-customer-service-demo-us-mob.mp4
	//to:
	//http://usphlvm1016.phl.sap.corp:6060/endpoint.epx?npcpid=7&dir=/demos/sap-crm-deliver-superior-customer-service-demo-us-mob.mp4
	var pp = mobilePath.split('/');
	var pp2 = "";
	for (x=4; x<pp.length; x++) {
		pp2 += "/" + pp[x];
	}
	var pu = "/endpoint.epx?npcpid=7&dir=" + pp2;
	return(pu);
}


function checkIfFileExists(mPath, trueFunc, falseFunc) {
	//follows the mPath and gets just the header. Returns true if there's a success, false if there's an error (file not found)
	//DOES NOT WORK CROSS DOMAIN.
	//alert('mPath: ' + mPath)
	ajaxPreloader(true);
	$.ajax({
		url:mPath,
		type:'HEAD',
		error:
			function(){
				//File Does Not Exist
				//alert('File Does Not Exist');
				
				//This function will probably NEVER fire if using the proxy. 
				//The endpoint proxy ALWAYS returns a string if the file is not found.
				
				ajaxPreloader(false);
				eval(falseFunc);
			},
		success:
			function(data){
				//File Exists. 
				//alert('File Does Exist');
				
				//Do nothing. Read the header on the complete function.
				//proxy ALWAYS returns a success.
				
				ajaxPreloader(false);
			},
			complete: function (XMLHttpRequest, textStatus) {
				var headers = XMLHttpRequest.getAllResponseHeaders().split("\n");
				var new_headers = {};
				var l = headers.length;
				for (var key=0;key<l;key++) {
					if (headers[key].length != 0) {
						header = headers[key].split(": ");
						new_headers[header[0].toLowerCase()] = header[1];
					}
				}
				
				/*$.each(new_headers, function(key, value) { 
				  alert('header: ' + key + ': ' + value); 
				});*/
				
				if (new_headers['content-length']  == 53) {
					//alert('404');	
					eval(falseFunc);
				} else {
					//alert('file exists');
					eval(trueFunc);
				}
			}
	});	
}

function ajaxPreloader(onORoff) {
	//Adds and removes the ajax preloader while we wait for the return from the checkforfile function
	//true or false?
	if (onORoff) {
		//Make ajax Preloader thingie
		var ajaxPreHTML = '<div id="ajaxpreloaderLayer" class="preLoaderLayerCSS" style="z-index:43px;"><center>Checking For Mobile Version<br/><br/><img src="/global/images/rm_images/rm_blue_preloader.gif"></center></div>';
		$(ajaxPreHTML).appendTo("body");	
		pWidth = 90;
		margs = pWidth/2 * -1;
		$("#ajaxpreloaderLayer").css({"height" : pWidth + 'px', 'width' : pWidth + 'px', 'background-color' : '#FFFFFF', 'z-index' : '43', 'margin-top' :  margs + 'px', 'margin-left' : margs + 'px', 'padding-left' : '10px', 'padding-top' : '10px', 'padding-right' : '10px'});	
		$("#ajaxpreloaderLayer").css({'border-width':'.2em', 'border-style':'solid', 'border-color':'#000000'});	
	} else {
		//Remove the ajax Preloader
		$("#ajaxpreloaderLayer").remove();
	}
}



//myString.trim()
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}


function showDesc(theDescriptionHTML) {
	
	if (qsParm['rm_descToggle'] == 'true') {
		tempData = unescape(theDescriptionHTML);
		var headline = unescape(arguments[1]);
		var subheadline = unescape(arguments[2]);
		
		//Find the IMG tag in the string
		lArray = tempData.split('id="logoImage">');
		lArray2 = lArray[1].split('</li>');
		logoHTML = lArray2[0].trim();
		
		//find the TEXT tag in the string
		tArray = tempData.split('id="text">');
		tArray2 = tArray[1].split('</li>');
		textHTML = tArray2[0];
		
		var insertHTML = ""; //Must define var as "" or else it's UNDEFINED
		
		if (logoHTML != '<img src="/global/images/spacer.gif"/>') {
			insertHTML = '<div id="movieLogo">' + logoHTML + '</div>';
		}
		
		if (headline != 'null' && subheadline != 'null') {
			insertHTML += '<div id="movieDescription"><h3>' + headline + '</h3><br/><p><b>' + subheadline + '</b><br/>';
		}
		insertHTML += textHTML + '</p></div>';
	
		$("#up_left").css({"visibility" : "visible", 'display' : 'block', "width" : "190px", "margin-left" : "16px", "margin-top" : "16px"});
		
		//IE6 doesn't do display:block and float:left - needs to be display:inline. (god, I hate you IE6)
		if ((BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6)) {	
			$("#up_left").css({'display' : 'inline'});
		}
		
		//apply Dove class
		$("#up_left").addClass('Dove');
		$("#up_left").html(insertHTML);
		
		//Description CSS fixes.
		$("#movieDescription h3").css({"margin-top" : "0px"});
		$("#movieDescription p").css({"margin-top" : "10px"});
		if (logoHTML != '<img src="/global/images/spacer.gif"/>') {
			$("#movieLogo").css({"margin-bottom" : "20px"});
		}
		
		centerDiv('UPcontainer');
	
	}
}



function makeUPdiv(someData) {
	//This makes the UP Div
	if (isiPad || qsParm['rm_iPadToggle'] == 'true') {
		//makeUniversalPlayerDiv('placeUPcode()', 'closeButton=true');
		alert("makeUniversalPlayerDiv('placeQT()', 'closeButton=true');");
		makeUniversalPlayerDiv('placeQT()', 'closeButton=true');
		
	} else {
		makeUniversalPlayerDiv('placeUPcode()');
	}
}

function blackDivClicked() {
	//09.29.10
	var theSWFage = getSWF("rmDHTMLplayer");
	if (theSWFage == undefined) {	
		theSWFage = getSWF("sapMediaPlayer");
	}
	if (theSWFage == undefined) {	
		theSWFage = getSWF("sapMediaPlayer_top");
	}
	if (theSWFage == undefined) {
		removeBlackOverlay();
		removeUPdiv();
	} else {
		theSWFage.remoteClose();
	}
	
}


function closeBlackDiv() {
	removeBlackOverlay();
	removeUPdiv();
}


function placeUPcode() {
	
	
	var theLayerCode = 	makeSWFhtmlDiv(mp_bLayer, UP_width, UP_height);
	
	$("#up_main").css({'float' : 'left', 'width' : UP_width + 'px'});
	$('#up_main').html(theLayerCode);
	$("#up_main").css({"height" : UP_height + "px"});
	
	if (UP_chaptering == "true") {
		if ((BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6)) {	
			//IE6 only code
			$('#up_left').html('<div id="chapteringDiv"></div>');
			$("#up_left").css({"visibility" : "visible", 'display' : 'inline'}); //, 'float' : 'left'
			$("#up_left").css({"margin-top" : "16px", 'margin-left' : '16px', 'margin-right' : '16px'});
			
			//UP_width has to be smaller for IE6
			$("#up_left").css({"width" : "200px"});	
		} else {
			//Non IE6 browser CSS fixes
			$('#up_left').html('<div id="chapteringDiv"></div>');
			$("#up_left").css({"visibility" : "visible", 'display' : 'block'}); //, 'float' : 'left'
			$("#up_left").css({"margin-top" : "16px", 'margin-left' : '16px', 'margin-right' : '16px'});
			
			leftOverWidth = 940 - UP_width;
			$("#up_left").css({"width" : leftOverWidth + "px"});
		}
	}

	
	centerDiv('UPcontainer'); 


	mediaPlayerBuilder2(mp_tLayer, mp_bLayer, "rmDHTMLplayer", "flashData", UP_width, UP_height, UP_location, UP_options);
	
	der = setInterval(rm_playIt, 500);
	
}




function make_rm_qt(qt_movSRC, qt_movWidth, qt_movHeight) {
	//Preps the RME for QT.
	movSRC = qt_movSRC;
	movWidth = qt_movWidth;
	movHeight = qt_movHeight;
	showBlackOverlay("makeQTlayer()", "blackDivClicked();");

}

function makeQTlayer()  {
	makeUniversalPlayerDiv('placeQT()', 'closeButton=true');
}

function placeQT() {
	
	qtw = parseInt(movWidth) + 32;
	qth = parseInt(movHeight) + 16;
	
	$("#up_main").css({'float' : 'left', 'width' : qtw + 'px'});
	$("#up_main").css({"height" : qth + "px"});
	
	
	qt_html = "";
	
	//Hardcoded - works: It's a crossdomain issue...
	//qt_html += "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='qtplugin.cab' height='380' width='640'><embed src='/demos/mmov/media/mexgrocer-growth-and-sap.mp4' autoplay='true' height='380' width='640' type='video/quicktime' pluginspage='download' /></object>";
	//alert(qt_html);
	
	//X DOMAIN!
	qt_html = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='qtplugin.cab' height='" + movHeight + "' width='" + movWidth + "'><embed src='" + movSRC + "' autoplay='true' height='" + movHeight + "' width='" + movWidth + "' scale='tofit' type='video/quicktime' pluginspage='download' /></object>";
	//alert(qt_html);
	
	//Original:
	/*qt_html += "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='qtplugin.cab' height='" + movWidth + "' width='" + movHeight + "'>";
	//qt_html += '<EMBED SRC="' + movSRC + '" WIDTH=' + movWidth + ' HEIGHT = ' + movHeight + ' autoplay=true scale="tofit" CONTROLLER=true LOOP=false PLUGINSPAGE=http://www.apple.com/quicktime/">';
	qt_html += '<embed src="' + movSRC + '" width="' + movWidth + '" height = "' + movHeight + '" autoplay="true" scale="tofit" pluginspage="download" />';
	//<embed src='/demos/mmov/media/mexgrocer-growth-and-sap.mp4' autoplay='true' height='380' width='640' type='video/quicktime' pluginspage='download' />
	
	qt_html += "</object>";*/
	
	$('#up_main').html(qt_html);
	
	if(wsdlToggle == "true"){
		makeAMovies(0);	
	}
	
	centerDiv('UPcontainer'); 
}




function makeAMovies(theMargin) {
	//This makes the WSDL assossiated movies div and places it in up_bottom
	
	//Placed INLINE for DEV - 07.12.10
	//var insertHTML = "";
	//insertHTML += "<div id='wsdlArea'>Place WSDL here</div>";
	
	//Get the total width for below...
	bWidth = "640px";
	$("#up_bottom").css({"visibility" : "visible", 'display' : 'block', "width" : bWidth, "margin-left" : theMargin + "px", "margin-top" : "16px", "margin-bottom" : "16px", "margin-right" : "16px"});
		
	//IE6 doesn't do display:block and float:left - needs to be display:inline. (god, I hate you IE6)
	if ((BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6)) {	
		$("#up_bottom").css({'display' : 'inline'});
	}
	
	//Placed INLINE for DEV - 07.12.10
	//$("#up_bottom").html(insertHTML);
	wsdlCode('1ea24763-2e2b-40ef-b759-f9a0346e5b5c');
	
}



function rmLoadNewMovie(movieURL) {
	var theSWFage = getSWF("rmDHTMLplayer");
	if (theSWFage == undefined) {	
		theSWFage = getSWF("sapMediaPlayer");
	}
	if (theSWFage == undefined) {	
		theSWFage = getSWF("sapMediaPlayer_top");
	}
	//alert(theSWFage);
	theSWFage.loadNewMedia(movieURL); 
}


function resetStream() {
	theSWFage = getSWF("rmDHTMLplayer");
	if (theSWFage == undefined) {	
		theSWFage = getSWF("sapMediaPlayer");
	}
	if (theSWFage == undefined) {	
		theSWFage = getSWF("sapMediaPlayer_top");
	}
	theSWFage.restartStream('junk'); 
}

function embedMobile() {
	//For embededing mobile videos:
	//alert('embedMobile function fired!');
	topLayerTP = arguments[0];
	flashLayer = arguments[1];
	flashObjectName = arguments[2];
	flashDataDiv = arguments[3];
	swfWidth = arguments[4];
	swfHeight = arguments[5];
	dataLocation = arguments[6];
	
	theOptions = arguments[7];
	
	//alert('dataLocation: ' + dataLocation);
	//Parse Options:
	var parsedOpts = new Array();

	var params = theOptions.split(',');
	for (var i=0; i<params.length; i++) {
		var pos = params[i].indexOf('=');
		if (pos > 0) {
			var key = params[i].substring(0,pos);
			var val = params[i].substring(pos+1);
			parsedOpts[key] = val;
		}
	}
	
	pauseAtStart = parsedOpts['pausedAtStart'];
	pauseImage = parsedOpts['pauseImage'];
		
	qtSRC = dataLocation;
		
	if (pauseImage) {
		theLayerCode = '<div id="thePauseImage"><a href="" onClick="embedTheQT(\'' + qtSRC + '\', ' + swfWidth + ', ' + swfHeight + ');return false;"><img src="' + pauseImage + '" width="' + swfWidth + '" height="' + swfHeight + '" border="0"/></a></div>';
		$('#' + flashLayer).html(theLayerCode);	
		//Must Make the layer Visible
		var swf = getLayer(flashLayer);
		swf.className = "div.visible";
	} else {
		//alert('no pause image');
		//alert(dataLocation);
		embedTheQT(dataLocation, swfWidth, swfHeight);
	}
}

function embedTheQT(movSRC, movWidth, movHeight) {
	//alert('embedTheQT fired');
	mPath = getMobileVideoPath(movSRC);
	//alert('movSRC:' + movSRC + ' mPath= ' + mPath);
	pPath = getProxyPath(mPath);
	//alert('getProxyPath: ' + pPath);
	//theLayerCode += '<div class="rm_textDisplay" id="rm_videoLink">Checking For Mobile Version...</div>';
	//$('#' + flashLayer).html(theLayerCode);	
	//alert('!: ' + pPath);
	fileExists = checkIfFileExists(pPath, 'embedTheQT_X()', 'noMovie_X()');	
}

function embedTheQT_X() {
	//alert('embedTheQT_X() fired.');
	if (doMobile) {
		this.location.href = mPath;
		//document.location.href=mPath
	} else {
		
		qt_html = "<object classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B' codebase='qtplugin.cab' height='" + swfHeight + "' width='" + swfWidth + "'><embed src='" + mPath + "' autoplay='true' height='" + swfHeight + "' width='" + swfWidth + "' scale='tofit' type='video/quicktime' pluginspage='download' /></object>";
		$('#' + flashLayer).html(qt_html);	
		
		//Make Layer Visible:
		var swf = getLayer(flashLayer);
		swf.className = "div.visible";
	}
}

function noMovie_X() {
	//alert('no movie');
	theLayerCode = '<div><p>We are sorry, but the video you have selected has not be converted to play on your mobile device.</p></div>';
	$('#' + flashLayer).html(theLayerCode);
}



function demosInPath(path) {
	id = false;
	sl = path.indexOf("/", 1);
	ddir = path.substring(1, sl);
	if (ddir.toLowerCase() == "demos") {
		id = true;	
	}
	return(id);
}


function createExperience() {
	//alert('createExperience fired');
	var sourceLocation;
	var playerType = 'dhtml_XHTML'; //dhtml_XHTML, etc...
	var parameterList;
	
	sourceLocation = arguments[0];
	playerType = arguments[1];
	parameterList = arguments[2];
	
	//alert('parameterList: ' + parameterList);
	
	if (isiPad || qsParm['rm_iPadToggle'] == 'true') {
		
		var parsedParm = parseString(parameterList);
		movWidth = parsedParm['width'];
		movHeight = parsedParm['height'];
		movSRC = getMobileVideoPath(sourceLocation);
		wsdlToggle = parsedParm['wsdlToggle'];
		
		//Check For Mobile if required!
		if (qsParm['rm_isMobile'] == 'true') {
			showBlackOverlay("make_QT_UP_div('isiPad');", "blackDivClicked();");
		} else {
			pPath = getProxyPath(movSRC);
			fileExists = checkIfFileExists(pPath, 'qtExists_Embed()', 'placeNoMovie_X()');	
		}
		
	//} else if (isiPhone || isAndroid || isPalm || qsParm['rm_iPhoneToggle'] == 'true') {
	//	alert('mobile! dont launch it.');
		
	} else {
		//operate normally.
		openMediaPlayer2(sourceLocation,playerType,parameterList);
	}
	
}

function qtExists_Embed() {
	showBlackOverlay("make_QT_UP_div('isiPad');", "blackDivClicked();");
}


function make_QT_UP_div() {
	makeUniversalPlayerDiv('placeQTinDiv()', 'closeButton=true');
}

function placeQTinDiv() {
	placeQT();
}




function delayedOpen() {
	if (qsParm['rm_autoLaunch'] == 'true') {		
		if (!qsParm['src']) {
			var tURL = location.href.split('?');
			theSource = tURL[0];
			//theSource = '/demos/rm_testing/rm_player/rm_simplePlayer_01.epx';
			thedL = 'dhtml_XHTML';
		} else {
			theSource = qsParm['src'];
			thedL = qsParm['dL'];
		}
		
		var funcParams = "";
		for (key in qsParm) {
			 if (key != "rm_autoLaunch" && key != "src" && key != "dL") {
				 funcParams += key + "=" + qsParm[key] + ","; //Add each of the query string parameters (except autoLaunch)
			 }
		}
		
		funcParams = funcParams.substring(0, funcParams.length - 1);
		//openMediaPlayer2(theSource,thedL,funcParams);
		
		createExperience(theSource,thedL,funcParams);
	}
}


function autoOpenRMlayer() {
	//mediaPlayerRemoteCall('sapMediaPlayer_top', 'playpause');
	dOpenInt = setTimeout(delayedOpen, 200);
} 

var dOpenInt;
addLoadEvent(autoOpenRMlayer);

