// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// 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_lastPath = null;
var g_lastId = null;
var g_lastChannelId = null;
var g_isIE = (window.navigator.userAgent.indexOf("MSIE")>0);
function playWMV(path, x, y, volume)
{
	g_lastPath = path;
	if(g_isIE)
	{
		var wmp = document.getElementById("wmppane");
		wmp.style.left = x + "px";
		wmp.style.top = y + "px";
		wmp.style.display = "";
		wmp = wmp.contentWindow.document.getElementById("wmpMain");
		wmp.url = path;
		wmp.settings.volume = volume;
	}
	else
	{
		/*var wmp = document.getElementById("wmppane");
		wmp.style.left = x + "px";
		wmp.style.top = y + "px";
		wmp.style.display = "";
		wmp.contentWindow.writeWMP(path,270,null,null,null,null,null,null,false)
		return;
		*/
		var win = window.open("popupplayer.jsp","wmvplayer","scrollbars=yes,menubar=no,height=270,width=480,top=0,left=0,resizable=no,toolbar=no,location=no,status=yes");
		if(win!=null)
			win.focus();
	}
}
function wmpProxy(action, value)
{
	if(g_isIE)
	{
		var wmp = document.getElementById("wmppane").contentWindow.document.getElementById("wmpMain");
		switch(action)
		{
		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 "shareshow":
			document.getElementById("wmppane").style.display = "none";
			break;
		case "sharehide":
			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":
			wmp.controls.stop();
			document.getElementById("wmppane").style.display = "none";
		}
	}
}
function popupReady(win)
{
	win.playWMV(g_lastPath, g_lastId, g_lastChannelId);
}

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 launchPopout(url)
{
	var win = window.open(url,"_blank","scrollbars=yes,menubar=no,height=371,width=480,top=0,left=0,resizable=yes,toolbar=no,location=no,status=yes");
	if(win!=null)
		win.focus();
}

var g_armyVideoName = null;
function writeFlexPlayer(isProduction, teamName, locale, embed, popout)
{
	var serverStr = "server=";
	var consoleStr = "console";
	if(embed)
		consoleStr = "embed";
	else if(popout)
		consoleStr = "popout";
	if(isProduction)
	{
		serverStr = "server=http://"+teamName+".nhl.tv/team/";
		consoleStr = "http://nhl.cdn.neulion.net/u/team/console";
		if(embed)
			consoleStr = "http://nhl.cdn.neulion.net/u/team/embed";
		else if(popout)
			consoleStr = "http://nhl.cdn.neulion.net/u/team/popout";
	}
	if(locale!=null && locale!="en_US")
		consoleStr += "_fr_CA";
	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;
		//var swfHeight = 952;
		var swfHeight = "100%";
		var brandColor = "0x24B1FF";
		switch(teamName)
		{
		case "canadiens":
			if(locale!=null && locale!="en_US")
				brandColor = "0x0C2360";
			break;
		case "coyotes":
			brandColor = "0x6C111C";
			break;
		case "hurricanes":
			brandColor = "0xCC0000";
			break;
		case "islanders":
			brandColor = "0xDE6000";
			break;
		case "flyers":
			brandColor = "0xFF6633";
			break;
		case "senators":
			brandColor = "0xC59217";
			break;
		case "sharks":
			brandColor = "0xF4911E";
			break;
		case "stars":
			brandColor = "0xA69310";
			break;
		case "www":
		case "nhl":
			//swfHeight = 870;
		}
		if(popout)
			swfHeight = "100%";
		if(g_armyVideoName!=null)
			flashVars[flashVars.length] = "armyvideoname="+g_armyVideoName;
		flashVars[flashVars.length] = "brandpath=http://nhl.cdn.neulion.net/u/team/";
		flashVars[flashVars.length] = "brandcolor="+brandColor;
		if(locale!=null && locale!="en_US")
			flashVars[flashVars.length] = "isfrench=true";
		if(window.location.search.length>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", swfHeight,
				"align", "middle",
				"id", "console",
				"quality", "high",
				"bgcolor", "#000000",
				"name", "console",
				"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 linkDigg()
{
	window.open("http://digg.com/submit?phase=2&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title), "digg", "scrollbars=yes,toolbar=no,width=800,height=600");
}
function linkDelicious()
{
	window.open("http://del.icio.us/post?v=4&noui&jump=close&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title), "delicious", "toolbar=no,width=700,height=400");
}

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 launchSupport()
{
	var team="";  // Generic
	var host = location.hostname.split(".");
	if(host.length==3)
	{
		switch(host[0])
		{
		case "ducks":
			team = "Anaheim Ducks";
			break;
		case "thrashers":
			team = "Atlanta Thrashers";
			break;
		case "bruins":
			team = "Boston Bruins";
			break;
		case "sabres":
			team = "Buffalo Sabres";
			break;
		case "flames":
			team = "Calgary Flames";
			break;
		case "hurricanes":
			team = "Carolina Hurricanes";
			break;
		case "blackhawks":
			team = "Chicago Blackhawks";
			break;
		case "avalanche":
			team = "Colorado Avalanche";
			break;
		case "bluejackets":
			team = "Columbus Blue Jackets";
			break;
		case "stars":
			team = "Dallas Stars";
			break;
		case "redwings":
			team = "Detroit Red Wings";
			break;
		case "oilers":
			team = "Edmonton Oilers";
			break;
		case "panthers":
			team = "Florida Panthers";
			break;
		case "kings":
			team = "Los Angeles Kings";
			break;
		case "wild":
			team = "Minnesota Wild";
			break;
		case "canadiens":
			team = "Montreal Canadiens";
			break;
		case "predators":
			team = "Nashville Predators";
			break;
		case "devils":
			team = "New Jersey Devils";
			break;
		case "islanders":
			team = "New York Islanders";
			break;
		case "rangers":
			team = "New York Rangers";
			break;
		case "senators":
			team = "Ottawa Senators";
			break;
		case "flyers":
			team = "Philadelphia Flyers";
			break;
		case "coyotes":
			team = "Phoenix Coyotes";
			break;
		case "penguins":
			team = "Pittsburgh Penguins";
			break;
		case "sharks":
			team = "San Jose Sharks";
			break;
		case "blues":
			team = "St. Louis Blues";
			break;
		case "lightning":
			team = "Tampa Bay Lightning";
			break;
		case "mapleleafs":
			team = "Toronto Maple Leafs";
			break;
		case "canucks":
			team = "Vancouver Canucks";
			break;
		case "capitals":
			team = "Washington Capitals";
			break;
		}
	}
	open(
			'http://gclsupport.nhl.com/link3/gcl/gcl-support.nsf?open&team=' + encodeURIComponent(team),
			'_blank',
			'width=1014,status=1,toolbar=1,location=1,menubar=1,directories=1,resizable=1,scrollbars=1'
		);
}