// JavaScript Document
var promotion_id = 1310;
var sessID = "LIVE003_v2";
var playerProps = ""


/*
 call launch with one, three or four parameters:
 Case 1: sessID
 	call with sessID only to launch player with bandwidth selector
 Case 2:
 	call with sessID,rate,player,[preview || full]  to launch a specific stream
 
 The streamInfoVars.asp file has variables to further customize available plugins and bandwidths.
 
 Note: although the fourth parameter refers explicitly to preview or full presentations, this is arbitrary, and 
 could be used to customize playlist filenames in any way.
 
*/
var playerPrefCookie = new Cookie(document, "playerPrefs", 0, "/");
playerPrefCookie.load();
var selectedRate = (exists(playerPrefCookie.rate)) ? playerPrefCookie.rate : false;
var detectedPlayer = (exists(playerPrefCookie.player)) ? playerPrefCookie.player : false;

// override these in the page to change defaults.
var playerWidth  = 640;
var playerHeight = 482;

function launch2(sessID, sessType, rate, player )
{

	var winName 	= "playerWin";
	var win;
	var w = screen.availWidth;
	var h = screen.availHeight;
	var chooseWidth  = 300;
	var chooseHeight = 150;

	if (typeof promotion_id == "undefined") alert("undefined promotion id for point player launch!")
	
	if (arguments.length < 4)
	{
		var leftPos = (w - chooseWidth) / 2;
		var topPos  = (h - chooseHeight) / 2;
		var ref 	= "http://www.livevault.com/demo_insync/detect.asp?sessID=" + sessID  + "&pid=8" + "&sessType=" + sessType + "&root=" + root;//http://www.demosondemand.com/shared_components/asp/player/
		ref += "&imagesPath="
		ref += "&promotion_id=" + promotion_id
		//alert(ref)
		win = window.open(ref, "detect", 'resizable=yes,' + chooseProps + ',top=' + topPos + ',left=' + leftPos);
		win.focus()
		
	} else {
		var leftPos = (w - playerWidth) / 2;
		var topPos  = (h - playerHeight) / 2;
		var ref = root + "http://www.livevault.com/demo_insync/index.asp?sessID=" + sessID;
		ref += "&rate=" + rate;
		ref += "&player=" + player;
		ref += "&sessType=" +sessType;
		if (typeof promo_id != "undefined")
		{
			ref += "&promotion_id=" + promo_id
		} else {
			ref += "&promotion_id=" + promotion_id
		}
//		alert(ref)
		if (typeof playerProps == "undefined")
		{
			win = window.open(ref, winName, 'width=' + playerWidth + ',height=' + playerHeight + ',top=' + topPos + ',left=' + leftPos);
		} else {
			win = window.open(ref, winName, playerProps + ',top=' + topPos + ',left=' + leftPos)
		}
		win.focus()
	} 
	return win;
}

function launchPoint(sessID, sessType, rate, player )
{
	if (arguments.length < 4)
	{
		//alert("rate in launch "  +selectedRate)
		//alert("player " + detectedPlayer)
		if (selectedRate && detectedPlayer)
		{
			launch2(sessID, sessType, selectedRate, detectedPlayer)
		} else {
			
			// if not passed explicit args, look for them in the cookie....
			if (typeof playerPrefCookie != "undefined")
			{
				
				if (playerPrefCookie.rate != "" && typeof playerPrefCookie.rate != "undefined" && playerPrefCookie.player != "none")
				{
					launch2(sessID, sessType, playerPrefCookie.rate, playerPrefCookie.player)
				} else {
					launch2(sessID, sessType)
				}
			} else {
				launch2(sessID, sessType)
			}
		}
	} else {
		launch2(sessID, sessType, rate, player)
	}
	return false;
}




// Note: this function is dependant on the Cookie class, defined elsewhere in this directory.
function launchDetect(sessID, companyID, promoID)
{
	/*
	if (playerPrefCookie.rate != "")
	{
		var leftPos = (screen.availWidth - ) / 2;
		var topPos  = (screen.availHeight - ) / 2;
	 	window.open("?&rate=" + rate + "&player=" + which, "playerWin", 'width=,height=,top=' + topPos + ',left=' + leftPos);
	
	} else 
	*/
	var pid = ''
	if ( (exists(playerPrefCookie.rate) && playerPrefCookie.rate < 150) || (exists(selectedRate) && selectedRate < 150))
	{
		var detectWidth = 300;
		var detectHeight = 150
		var leftPos = Math.round((screen.availWidth - detectWidth) / 2);
		var topPos  = Math.round((screen.availHeight - detectHeight) / 2);
		var ref = "http://www.livevault.com/demo_insync/detect.asp?playerType=training&sessID=" + sessID + "&pid=8";//http://www.demosondemand.com/shared_components/asp/player/
		if (arguments.length > 1) ref += "&companyID=" + companyID
		if (pid != '')
		{
			ref += "&promotion_id=" + pid;
		} else {
			ref += "&promotion_id=" + promotion_id;
		}
		//alert(ref)
		var win = window.open(ref, "detect", 'width=' + detectWidth + ',height=' + detectHeight + ',top=' + topPos + ',left=' + leftPos);
		win.focus()
	} else {
		launch(sessID, companyID)
	}
	return false;
}

function launchWarning(sessID, companyID)
{
	var detectWidth = 400;
	var detectHeight = 225
	var leftPos = Math.round((screen.availWidth - detectWidth) / 2);
	var topPos  = Math.round((screen.availHeight - detectHeight) / 2);
	var ref = "http://www.demosondemand.com/shared_components/asp/player/warning.asp?warn=training&sessID=" + sessID;
	if (arguments.length > 1) ref += "&companyID=" + companyID;
	var win = window.open(ref, "warning", 'width=' + detectWidth + ',height=' + detectHeight + ',top=' + topPos + ',left=' + leftPos);
	win.focus()
	return false;
}



function launch(sessID, companyID)
{

	var playerWidth  = 1000;
	var playerHeight = 709;


	var win;
	var ref = "http://www.livevault.com/demo_insync/player/index.asp?sessID=" + sessID + "&pid=8";
	//if (arguments.length > 1) ref += "&companyID=" + companyID;
	
	if (typeof promotion_id == "undefined")
	{
		alert("Page missing default promo id!")
		return false
	} else {
		ref += "&promotion_id=" + promotion_id
	}
	

	try
	{

		win = window.open(ref, "player", 'width=' + playerWidth + ',height=' + playerHeight + ',top=1,left=1');
		win.focus()

	} catch(e) {
		document.location = ref;
		return true;
	}

	return false;
}

var demoWin;
function launchWithStartTime(sessID, promoID, startTime)
{

	var playerWidth  = 1000;
	var playerHeight = 709;

	
	var ref = "http://www.demosondemand.com/TrainingApp/player/index.asp?sessID=" + sessID;
	ref += "&cid=" + promoID;
	ref += "&promotion_id=" + promoID
	ref += "&startTime=" + startTime
	
//alert(ref)
	if (typeof demoWin != "undefined") demoWin.close();
	
	
	try
	{
	
		
		var hWnd = window.open(ref, "demoWin", 'width=' + playerWidth + ',height=' + playerHeight + ',top=1,left=1');
		hWnd.focus()
	
	} catch(e) {
		
	// window.open throws a catchable error if popup blocking software is installed.
		// in this case, load the player into the already open window, and resize accordingly.
		if (typeof window.opener != "undefined" && typeof window.opener.promotion_id != "undefined")
		{
			resizeWindow(playerWidth, playerHeight + 30)
		} else {
			resizeWindow(playerWidth, playerHeight + 200)
		}
		window.moveTo(0,0)
		document.location = ref;
		return true;
	}
	
	return false;
}