// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 28;
// -----------------------------------------------------------------------------

// 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_lastPath = null;
var g_isIE = (window.navigator.userAgent.indexOf("MSIE")>0);
function playWMV(path, x, y, volume, trackCG, trackTL)
{
	if(path.indexOf("?")>0)
		path += "&nopr=1";
	else
		path += "?nopr=1";
	g_lastPath = path;
	var wmp = document.getElementById("wmppane");
	if(g_isIE)
	{
		wmp.style.left = x + "px";
		wmp.style.top = y + "px";
		wmp.style.display = "";
		wmp = document.getElementById("wmppane");
		wmp = wmp.contentWindow.document.getElementById("wmpMain");
		wmp.url = path;
		wmp.settings.volume = volume;
	}
	else
	{
		/*wmp.style.left = x + "px";
		wmp.style.top = y + "px";
		wmp.style.display = "";
		wmp = document.getElementById("wmppane");
		wmp.contentWindow.writeWMP(path,424,false,640,null,null,null,true,false);
		wmp = wmp.contentWindow.document.getElementById("wmpMain")
		*/
		var win = window.open("wmppop.htm","wmvplayer","scrollbars=yes,menubar=no,height=334,width=480,resizable=no,toolbar=no,location=no,status=yes");
		if(win!=null)
			win.focus();
	}
}
function wmpProxy(action, value)
{
	var wmp = document.getElementById("wmppane").contentWindow.document.getElementById("wmpMain");
	switch(action)
	{
	case "ff":
		wmp.controls.fastForward();
		break;
	case "fullscreen":
		wmp.fullScreen = true;
		break;
	case "stop":
		wmp.controls.stop();
		break;
	case "pause":
		wmp.controls.pause();
		break;
	case "play":
		wmp.controls.play();
		break;
	case "setvolume":
		wmp.settings.volume = value;
		break;
	case "getvolume":
		return wmp.settings.volume;
		break;
	case "rewind":
		wmp.controls.fastReverse();
		break;
	case "shareshow":
		if(g_isIE)
			document.getElementById("wmppane").style.display = "none";
		break;
	case "sharehide":
		if(g_isIE)
			document.getElementById("wmppane").style.display = "";
		break;
	case "position":
		var p = document.getElementById("wmppane");
		//p.style.left = value[0] + "px";
		p.style.top = value[1] + "px";
		break;
	case "ecm":
		wmp.enableContextMenu = true;
		break;
	case "hide":
		if(g_isIE)
		{
			wmp.controls.stop();
			document.getElementById("wmppane").style.display = "none";
		}
	}
}
function popupReady(win)
{
	win.playWMV(g_lastPath);
}

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 writeFlexPlayer(swfName, oemId, isProduction, tremorProgId, gaAccount, brandTextColor, siteBaseServer, secureBaseServer, imageCDN, embed, inline, nielsenCI)
{
	var serverStr = "server=" + location.href.substring(0, location.href.lastIndexOf("/")+1);
	var secureServerStr = serverStr;
	var consoleStr = imageCDN + "/siteMediaPlayer/3360/console";
	if(swfName!=null)
		consoleStr = imageCDN + "/siteMediaPlayer/3360/" + swfName;
	if(embed)
		consoleStr = "embed";
	if(isProduction)
	{		
		serverStr = "server=" + siteBaseServer + "XML/titanv3/";
		secureServerStr = "secureserver=" + secureBaseServer + "XML/titanv3/";	
	}
	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] = "tremorprogid="+tremorProgId;
		flashVars[flashVars.length] = serverStr;
		//flashVars[flashVars.length] = secureServerStr;
		flashVars[flashVars.length] = "jtv=" + oemId;
		flashVars[flashVars.length] = "gaa=" + gaAccount;
		//flashVars[flashVars.length] = "nielsenci=" + nielsenCI;
		//flashVars[flashVars.length] = "skin=" + oemId;
		flashVars[flashVars.length] = "brandTextColor=" + brandTextColor;
		flashVars[flashVars.length] = "nlwa=http://track1.neulion.com/uncclub/";
		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] = "referrer="+encodeURIComponent(document.referrer);
	
		// 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", "502",
				"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 = 'Alternate HTML content should be placed here. '
	  	+ 'This content requires the Adobe Flash Player. '
	   	+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
	    document.write(alternateContent);  // insert non-flash content
	  }
}

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 writeWMP(url, h, bDisableContextMenu, w, mute, containerId, id, notIEShowControls, windowless)
{
	if(h==null)
		h = 270;
	
	if(w==null)
		w = 480;
		
	if(mute==null)
		mute = false;
	
	if(bDisableContextMenu==null)
		bDisableContextMenu=true;
		
	if(notIEShowControls==null)
		notIEShowControls = true;
		
	if(windowless==null)
		windowless = true;

	var isie = window.navigator.userAgent.indexOf("MSIE")>0;
	var ismac = window.navigator.userAgent.indexOf("Mac")>0;

	var strUIMode="none";
	if (!isie && notIEShowControls)
		strUIMode="full";
	
	if(id==null)
		id = "wmpMain";
	
	var strHTML ='<object id="'+id+'" classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" type="application/x-oleobject" height="'+h+'" width="'+((isie)?"100%":w)+'">';
	if (bDisableContextMenu==true)
		strHTML+='<param name="enableContextMenu" value="false" />';
	strHTML+='<param name="autoStart" value="true" />';
	if(windowless)
		strHTML+='<param name="windowlessVideo" value="true" />';
	strHTML+='<param name="url" value='+url+' />';
	strHTML+='<param name="uiMode" value="'+strUIMode+'" />';
	strHTML+='<param name="mute" value="'+((mute)?"true":"false")+'" />';
	if(mute)
		strHTML+='<param name="volume" value="0" />';
	strHTML+='<embed type="';
	if(ismac)
		strHTML+='application/x-mplayer2';
	else
		strHTML+='application/x-ms-wmp';
	strHTML+='" src="'+url+'" autostart="true" showcontrols="1" height="'+h+'" width="'+w+'" mute="'+((mute)?"1":"0")+'"';
	if(mute)
		strHTML+=' volume="0"';
	strHTML += ' /></object>';

	if(containerId==null)
		containerId = "wmppane0";
	document.getElementById(containerId).innerHTML=strHTML;
}

var _rsdDN = "//secure-us.imrworldwide.com/";
var _rsdCI = "us-xostech";
var _rsdFQ = 10;
var _rsdSI = "null";
var _rsdTC = 0;
var _rsdPCG = 0;

function setJTVTokenCookie(key)
{
	try
	{
		if(key!=null)
			document.cookie = "jtvTokenCookie=" + escape(key);
		else
			document.cookie = "jtvTokenCookie=;expires=Fri, 31 Dec 1999 23:59:59 GMT;";
	}
	catch(e){}
}

function getJTVTokenCookie()
{
	if(document.cookie!=null && document.cookie.length>0)
	{
		var the_cookie = document.cookie;
		var crumbs = the_cookie.split(";");
		for(var i=0;i<crumbs.length;i++)
		{
			curCrumb = crumbs[i].split("=");
			if(curCrumb[0].indexOf("jtvTokenCookie")!=-1)   // Cookie was found
			{ 
				var val = unescape(curCrumb[1]);
				if(val!="undefined")			
				{
					return val;
				}
			}
		}
	}
	return null;
}

function iptvShowCompanions(playerX, playerY, companions)
{
	for(var i=0;i<companions.length;i++)
	{
		var adsize = companions[i][0];
		switch(adsize)
		{
		case "728x90":
			iptvShowTopCompanion(playerX, playerY, companions[i]);
			break;
		case "300x250":
			iptvShowSideCompanion(playerX, playerY, companions[i]);
			if(iptvCompanionDuration>0)
				setTimeout("iptvHideCompanions(true)", iptvCompanionDuration*1000);
			break;
		}
	}
}
function iptvHideCompanions()
{
	if(iptvCompanionDuration==0 || hide==true)
	{
		iptvHideSideCompanion();
	}
}
function iptvShowTopCompanion(playerX, playerY, companion)
{
	var oDiv=document.getElementById("iptvTopAdDiv");
	if (oDiv==null)
	{
		oDiv = document.createElement("div");
		oDiv.id = "iptvTopAdDiv";
		oDiv.style.width = "728px";
		oDiv.style.height = "90px";
		document.getElementById("topBannerDiv").appendChild(oDiv);
		oDiv.style.display = "none";
	}

	if("iframe"==companion[1] && companion[2]!=null)
	{
		var strAdHTML = "<iframe id='iptvTopIFrame' width='728' height='90' frameborder='0' scrolling='no' src='"+companion[2]+"'></iframe>";
		oDiv.innerHTML = strAdHTML;
		oDiv.style.display = "";
	}
	else
	{	
		oDiv.style.display="none";
	}
}
var iptv_aniSpeed = 8;           // Animation speed - bigger==faster
var iptvCompanionDuration = 0;
function iptvHideSideCompanion()
{
	var tbl = document.getElementById("iptvAdTbl");
	if (tbl != null)
	{
		if (!g_isIE && document.getElementById("iptvIFrame") != null)
			document.getElementById("iptvIFrame").style.display="none";

		document.getElementById("iptvAdContainer").style.display="";
		tbl.setAttribute("anim_destX", (-1 * tbl.offsetWidth));
		iptvStartAnimation(true);
	}
}

function iptvShowSideCompanion(playerX, playerY, companion)
{
	var adContainer = document.getElementById("iptvAdContainer");
	if (adContainer == null)
	{
		adContainer=document.createElement("div");
		adContainer.id="iptvAdContainer"
		adContainer.style.width="310px";
		adContainer.style.height="274px";
		adContainer.style.position="absolute";
		adContainer.style.overflow="hidden";
		document.body.appendChild(adContainer);

		var tbl = document.createElement("table");
		tbl.style.backgroundColor="#666666";
		tbl.id = "iptvAdTbl";
		tbl.cellPadding = "0";
		tbl.cellSpacing = "0";
		tbl.style.position = "absolute";
		tbl.style.top = "0px";
		tbl.style.width="310px";
		tbl.style.height="274px";
		var oRow1=tbl.insertRow(-1);
		var oCell = oRow1.appendChild(document.createElement("td"));
		oCell.style.width="100%";
		oCell.style.textAlign = "right";
		oCell.style.paddingRight="3px";
		oCell.innerHTML = "<a style='color:#FFFFFF;font-size:8pt;font-family:arial' href='javascript:iptvHideCompanions(true)'>CLOSE</a>";

		var oRow2=tbl.insertRow(-1);
		oRow2.style.height="100%";
		var oCell2 = oRow2.appendChild(document.createElement("td"));
		oCell2.align = "center";
		oCell2.vAlign = "middle";

		var oDiv = oCell2.appendChild(document.createElement("div"));
		oDiv.id = "iptvAdDiv";
		oDiv.style.width = "300px";
		oDiv.style.height = "250px";

		adContainer.appendChild(tbl);
	}

	var obj = document.getElementById("console");
	if(obj)
	{
		obj = obj.parentNode;
		// Position ad container
		var x_pos=0;
		var y_pos=0;

		var temp = obj;
		do
		{
			x_pos += temp.offsetLeft;
			y_pos += temp.offsetTop;
			temp = temp.offsetParent;
		}
		while(temp!=null)

		adContainer.style.left = (x_pos + playerX + 480 + 4) + "px";
		adContainer.style.top = y_pos + playerY - 2 + "px";

		// Set HTML for ad
		var strAdHTML = "";
		
		if("iframe"==companion[1] && companion[2]!=null)
		{
			strAdHTML = "<iframe id='iptvIFrame' width='300' height='250' frameborder='0' scrolling='no' src='"+companion[2]+"'></iframe>";
		}
		else if("swf"==companion[1] && companion[2]!=null)
		{
			strAdHTML = "<object width='300' height='250' id='iptvSWF' classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'><param name='movie' value='"+companion[2]+"' /><embed name='iptvSWF' pluginspage='http://www.adobe.com/go/getflashplayer' src='"+companion[2]+"' type='application/x-shockwave-flash' width='300' height='250'></embed></object>";
		}
		else if("img"==companion[1] && companion[2]!=null)
		{
		
			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>";
		}

		if (!g_isIE)
			document.getElementById("iptvAdDiv").style.display="none";
			
		document.getElementById("iptvAdDiv").innerHTML = strAdHTML;

		// Animate ad table within ad box
		var tbl = document.getElementById("iptvAdTbl");
		
		document.getElementById("iptvAdContainer").style.display="";
		tbl.style.left = (-1 * tbl.offsetWidth) + "px";
		tbl.setAttribute("anim_destX", 0);

		iptvStartAnimation(false);
	}

}
function iptvStartAnimation(bMoveIn)
{
	document.getElementById("iptvAdContainer").style.display="";
	iptvAnimateItem(bMoveIn);
}

function iptvAnimateItem(bMoveIn)
{
	var obj=document.getElementById("iptvAdTbl");

	var currLeft = obj.offsetLeft;

	var iTargetPosX = obj.getAttribute("anim_destX");
	if (iTargetPosX != null)
	{
		if ((bMoveIn && (currLeft - iptv_aniSpeed <= iTargetPosX)) || (!bMoveIn && (currLeft + iptv_aniSpeed >= iTargetPosX)))
		{
			obj.style.left = iTargetPosX + "px";  // Stop animating
			document.getElementById("iptvAdDiv").style.display="";
			if (bMoveIn)
				document.getElementById("iptvAdContainer").style.display="none";
		}
		else
		{
			if (bMoveIn)
			{
				if (document.getElementById("iptvAdContainer").style.display=="none")
					return;
				obj.style.left = currLeft - iptv_aniSpeed + "px";
				setTimeout("iptvAnimateItem(true)", 1);
			}
			else
			{
				obj.style.left = currLeft + iptv_aniSpeed + "px";
				setTimeout("iptvAnimateItem(false)", 1);
			}
		}
	}
}

var g_ppvWin=null;
function iptvShowPPV(url)
{
	g_ppvWin = window.open(url, "subWin");
    if (g_ppvWin)
    	g_ppvWin.focus();
    else
    	alert("Error - You must turn off all popup blockers to continue with subscription.");

	setTimeout("iptvCheckPPVClosed()", 3000);
}
function iptvCheckPPVClosed()
{
	if (window.g_ppvWin==null)
		return;
	
	if (!window.g_ppvWin.closed)
		setTimeout("iptvCheckPPVClosed()", 1000);
	else
		iptvPPVCallback(null);
}
function iptvPPVCallback(ret)
{
	document.getElementById("console").ppvClosed();
}
function iptvSetBackToLink(link, text)
{
	var str = "<a href='"+link+"'>&lt;&lt; Back to "+text+"</a>";
	document.getElementById("iptvBackToLink").innerHTML = str;
}