var omnitureProduction = true;

// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 10;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 0;
// -----------------------------------------------------------------------------

// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

var g_isIE = (window.navigator.userAgent.indexOf("MSIE")>0);

function getPageUrl()
{
	var url = window.location.href;
	var i = url.indexOf("?");
	if(i>0)
		url = window.location.href.substring(0,i);
	return url.substring(0,url.lastIndexOf("/")+1);
}
function getSessionId()
{
	var sid = "";
	if(document.cookie!=null && document.cookie.length>0)
	{
		var crumbs = document.cookie.split(";");
		for(var i=0;i<crumbs.length;i++)
		{
			var curCrumb = crumbs[i].split("=");
			if(curCrumb[0].indexOf("JSESSIONID")==0)
			{
				if(unescape(curCrumb[1])!="undefined")			
				{
					sid = unescape(curCrumb[1]);
					break;
				}
			}
		}
	}
	return sid;
}
function writeFlexPlayer(isProduction)
{
	var serverStr = "server=" + location.href.substring(0, location.href.lastIndexOf("/")+1);
	var consoleStr = "console";
	var locImage = "";
	if(isProduction=="true")
	{
		serverStr = "server=http://video.nhl.com/videocenter/";
		consoleStr = "http://nhl.cdn.neulion.net/u/videocenter/console";
		locImage = "http://nhl.cdn.neulion.net/u/videocenter/";
	}
	if ( hasProductInstall && !hasRequestedVersion ) {
		// MMdoctitle is the stored document.title value used by the installation process to close the window that started the process
		// This is necessary in order to close browser windows that are still utilizing the older version of the player after installation has completed
		// DO NOT MODIFY THE FOLLOWING FOUR LINES
		// Location visited after installation is complete if installation is required
		var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
		var MMredirectURL = window.location;
	    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
	    var MMdoctitle = document.title;
	
		AC_FL_RunContent(
			"src", "scripts/playerProductInstall",
			"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
			"width", "100%",
			"height", "100%",
			"align", "middle",
			"id", "console",
			"quality", "high",
			"bgcolor", "#000000",
			"name", "console",
			"allowScriptAccess","always",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
		);
	} else if (hasRequestedVersion) {
	
		var flashVars = new Array();
		if(g_isIE)
			flashVars[flashVars.length] = "isie=true";
		flashVars[flashVars.length] = serverStr;
		if(window.location.search.length>1)
		{
			flashVars[flashVars.length] = "qs=" + encodeURIComponent(window.location.search.substring(1));
			var nvs = window.location.search.substring(1).split("&");
			if(nvs.length>0)
			{
				for(var i=0;i<nvs.length;i++)
				{
					flashVars[flashVars.length] = nvs[i];
				}
			}
		}
		flashVars[flashVars.length] = "locimage="+locImage;
		flashVars[flashVars.length] = "referrer="+encodeURIComponent(document.referrer);
		flashVars[flashVars.length] = "nlwa=http://app2.neulion.com/videocenter/nhl/";
		if(!omnitureProduction)
			flashVars[flashVars.length] = "osca=nhlnhlleaguedev";
	
		// if we've detected an acceptable version
		// embed the Flash Content SWF when all tests are passed
		AC_FL_RunContent(
				"flashVars", flashVars.join("&"),
				"src", consoleStr,
				"width", "100%",
				"height", "100%",
				"align", "middle",
				"id", "console",
				"quality", "high",
				"bgcolor", "#000000",
				"name", "console",
				"wmode", "transparent",
				"allowFullScreen", "true",
				"allowScriptAccess","always",
				"type", "application/x-shockwave-flash",
				"pluginspage", "http://www.adobe.com/go/getflashplayer"
		);
	  } else {  // flash is too old or we can't detect the plugin
	    var alternateContent = 'This content requires the Adobe Flash Player. '
	   	+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
	    document.getElementById("nlFlexPlayerDiv").innerHTML = alternateContent;  // insert non-flash content
	  }
}
function iptvShowCompanions(playerX, playerY, companions)
{
	for(var i=0;i<companions.length;i++)
	{
		var adsize = companions[i][0];
		switch(adsize)
		{
		case "728x90":
			iptvShowCompanion("iptvTopAdDiv", playerX, playerY, companions[i], 728, 90);
			break;
		case "300x250":
			setAdMode(true);
			iptvShowCompanion("iptvAdDiv", playerX, playerY, companions[i], 300, 250);
			break;
		}
	}
}
function iptvShowCompanion(id, playerX, playerY, companion, w, h)
{
	var oDiv = document.getElementById(id);
	if("iframe"==companion[1] && companion[2]!=null)
	{
		oDiv.innerHTML = "<iframe width='"+w+"' height='"+h+"' frameborder='0' scrolling='no' src='"+companion[2]+"'></iframe>";
	}
	else if("img"==companion[1] && companion[2]!=null)
	{	
		var strAdHTML = "";
		if(companion[3]!=null && companion[3].length>0)
			strAdHTML = "<a href='"+companion[3]+"' target='_blank'>";
		
		strAdHTML += "<img src='"+companion[2]+"' border='0' />";

		if(companion[3]!=null && companion[3].length>0)
			strAdHTML += "</a>";
		
		oDiv.innerHTML = strAdHTML;
	}
}
function iptvHideCompanions(hide)
{
	setAdMode(false);
}