// 2002-9 Live365.com.  All rights reserved.
// PageHost Data structures

if (typeof(SniffWMP) != "function")
	document.write('<scr' + 'ipt language="JavaScript" src="/scripts/vb_sniff_lite.js"></scr' + 'ipt>');

var HostInfo = 
{ 
	////////////////////////////////////////////////////////////////////	
	// Radio365Win Host structure
	////////////////////////////////////////////////////////////////////	
	RADIO365_WIN: 
	{ 
		POC:			16,
		Name:			"RADIO365_WIN",  // used to be Start365
		HasPlayer:		false,  
		AllowDirLaunch:	true,
		bPreplay:		false,
		bHasFreeTrial:	true,

		LaunchStreamByName: function (bcname, site, args)
		{
			top.location = "http://" + gHostServer + "/cgi-bin/play.365e?station="+bcname+"&site="+site + args;
			return true;
		},

		LaunchStreamByID: function(id, site, args)
		{
			top.location = "http://" + gHostServer + "/cgi-bin/play.365e?stream_id="+id+"&site="+site + args;
			return true;
		},
		
		IsHost:function()
		{
			return (16 == parseInt(GetCookieEx('box_mc', "POC")));
		}, 

		//perform duties when the player page fully loads
		OnLoad: function()
		{
			//Do nothing							
		}
	}, 

	////////////////////////////////////////////////////////////////////
	// RealOne Host structure
	//
	// Realone hosts are only invoked when they are currently hosting
	// player switching should be disallowed in this mode, as it will 
	// have no effect. Streams are always played thru the host.
	////////////////////////////////////////////////////////////////////		
	G2_APP: 
	{ 
		POC:			11,
		Name:			"RealOne",  
		HasPlayer:		true,  
		AllowDirLaunch:	false,	// can the host be invoked when not hosting - Real should not be invoked
		bPreplay:		true,	// is the player ass over elbow ? Audio is invoked before metadata.
		bHasFreeTrial:	false,

		// check to see if RealOne is the current host
		IsHost:function()
		{
			try {
				if (parent && parent.external) {
					var rpv = typeof(parent.window.external.RealPlayerVersion);
					
					if (rpv != "undefined" && rpv != "unknown") {
						RememberItEx('box_mc', 'POC', 11);
						return true;
					}
				}
				
				return false;
			}
			catch(e) {
				return false;
			}
		},

		//Invoke a stream by the bc name
		LaunchStreamByName: function (bcname, site, args)
		{
			//setup navigation - should only happen first time someone clicks on the site
			//if the invoke comes from outside out site then navigation should occur
			RememberItEx('session_mc', 'noronav', '1', true);
			window.external.PlayClip("http://" + gHostServer + "/cgi-bin/mini.cgi?site=" + site + "&membername=" + bcname+"&templateid=smil"+ args);
			return true; 
		},				

		//Invoke a stream by the stream id
		LaunchStreamByID: function(id, site, args)
		{
			RememberItEx('session_mc', 'noronav', '1', true);
			window.external.PlayClip("http://" + gHostServer + "/cgi-bin/mini.cgi?site=" + site + "&stream=" + id + "&templateid=smil"+ args);
			return true;
		}, 

		//perform duties when the player page fully loads
		OnLoad: function()
		{
			//were we launched from our site?
			var flag = GetCookieEx('session_mc', 'noronav');
			if (flag == null || flag == "0") {
				var url = "http://" + gHostServer;
				 
				if (top.GetServerMode() == 'OD')
					url += "/stations/" + top.stationID;
				else {
					var genres = top.GetGenre().split(",");
					url += "/cgi-bin/directory.cgi?genre=" + genres[0]
				}

				window.parent.external.OpenURLInPlayerBrowser(url);
			}
			//override the framemessage
			if (top.frames["Live365PlayerFrameMessage"])
				top.frames.Live365PlayerFrameMessage.location = "/mini/realone.html";

            //clear out nav for next invoke
			RememberItEx('session_mc', 'noronav', '0', true);
		}
	},

	////////////////////////////////////////////////////////////////////
	// Radio365Mac Host structure
	////////////////////////////////////////////////////////////////////		
	RADIO365_MAC: 
	{ 
		POC:			14,  
		Name:			"RADIO365_MAC",  
		HasPlayer:		true,  
		AllowDirLaunch:	true,
		bPreplay:		false,
		bHasFreeTrial:	false,

		// check to see if we are the current host
		IsHost:function()
		{
			return (14 == parseInt(GetCookieEx('box_mc', "POC")));
		},  

		//Invoke a stream by the bc name
		LaunchStreamByName: function (bcname, site, args)
		{
			top.location = "p365://" + gHostServer + "/" + bcname;
			return true;
		},

		LaunchStreamByID: function(id, site, args)
		{
			top.location = "p365://" + gHostServer + "/" + id;
			return true;
		},
		
		OnLoad: function()
		{
		}
	},
	
	////////////////////////////////////////////////////////////////////
	// WMP 9+ - Windows Media Player, version 9 or better
	////////////////////////////////////////////////////////////////////		
	WMP_APP: 
	{ 
		POC:			12,  
		Name:			"WMP_APP",  
		HasPlayer:		true,  
		AllowDirLaunch:	true,
		bPreplay:		false,
		bHasFreeTrial:	false,

		// we are the current host if user has selected WMP and is running version 9 or 10
		IsHost:function()
		{
			return (12 == parseInt(GetCookieEx('box_mc', "POC")) && SniffWMP(9));
		},  

		//Invoke a stream by the bc name
		LaunchStreamByName: function(bcname, site, args)
		{
			var url = "http://" + gHostServer + "/cgi-bin/wmp.asx?site=wmp&name_type=nam&station=" + bcname;
			
			if (IsVista() && (!args || args.indexOf('pf=') == -1))
				args += "&pf=N";
				
			if (args)
				url += args;
				
			top.location.href = url;
			return true;
		},

		LaunchStreamByID: function(id, site, args)
		{
			var url = "http://" + gHostServer + "/cgi-bin/wmp.asx?site=wmp&name_type=str&station=" + id;
			
			if (IsVista() && (!args || args.indexOf('pf=') == -1))
				args += "&pf=N";
				
			if (args)
				url += args;
				
			top.location.href = url;
			return true;
		},
		
		OnLoad: function()
		{
		}
	}
};
	
// detect who is currently hosting the page
function GetHostApp()
{
	for (var v in HostInfo)	{	
		if (HostInfo[v].IsHost())
			return HostInfo[v];
	}
	return null;
}
		
//sniffing not allowed
//must rely on hosting cookies
function FindHostByID(poc)
{
 	for (var v in HostInfo) {
	 	if (HostInfo[v].POC == poc)
		 	return HostInfo[v];
 	}
 	return null;
}

//check by envirnoment		
function GetDirectLaunchHost()
{
	//hosting - check the volatile first, as this means we are in the 
	//host environment and it takes precednece
	
	//note - we should be able to do host detection here now.
	//check for volatile page host
	var vph = GetHostApp(); 
	if (vph != null) 
		return vph;
	
	// Nope ?
	// ok check the cookied host
	var poc = GetCookieEx('box_mc', 'POC');
	if (poc != null)  
		return FindHostByID(poc);

	return false; 
}


function PlayerIsDirectLaunch()
{
	return GetDirectLaunchHost() != null;
}


function IsVista()
{
	return (navigator.appName.indexOf("NT 6") != -1);
}

var HostEnabled = true;