//-----------------------------------------------------------------------
//Copyright (C) SFosterMurray. All rights reserved. Hacked from WMP 11
//SDK samples... thanks to Microsoft and the Internet--->
//Go visit http://www.emediacommunications.biz/sm5/articlesm5.html
//and http://support.microsoft.com/default.aspx?scid=kb;en-us;279022
//-----------------------------------------------------------------------
//BrowserWhiffer.js

//-----------------------------------------------------
//Globals: Everything starts here. [INIT]
//-----------------------------------------------------
var uAgent="unknown";
var appVer="unknown";
try
{
	if(navigator&&typeof(navigator.userAgent)=="string")
	{
		uAgent=navigator.userAgent.toLowerCase();
	}
	if(navigator&&typeof(navigator.appVersion)=="string")
	{
		appVer=navigator.appVersion.toLowerCase();
	}
}
catch(e)
{
}
//-----------------------------------------------------
//Globals: All Browser Identification Objects. [INIT]
//-----------------------------------------------------
var broswerId="unknown";
var browserVer="unknown";
var browserMajorVer="unknown";
var browserMinorVer="unknown";
var broswerEngine="unknown";
var broswerEngineVer="unknown";
//Go fill in the blanks DUDE!
try
{
	GetAllBrowserInformation();
}
catch(e)
{
}
//-----------------------------------------------------
//Globals: All OS Identifcation Information. [INIT]
//-----------------------------------------------------
var runningWin2K=null;
var runningWinXP=null;
var runningVista=null;
try
{
	runningWin2K=((uAgent.indexOf("windows nt 5.0")!=-1) || (uAgent.indexOf("windows 2000")!=-1));
	runningWinXP=((uAgent.indexOf("windows nt 5.1")!=-1) || (uAgent.indexOf("windows xp")!=-1));
	runningVista=((uAgent.indexOf("windows nt 6.0")!=-1) || (uAgent.indexOf("windows vista")!=-1));
}
catch(e)
{
}
//-----------------------------------------------------
//Globals: All HTML DOM Helper Objects. [INIT]
//-----------------------------------------------------
var htmlDOMgetElementById=null;
var htmlDOMgetElementsByTagName=null;
var htmlDOMdocumentElement=null;
var htmlDOMdocumentAll=null;
try
{
	htmlDOMgetElementById=(document.getElementById) ? "true" : "false"; 
	htmlDOMgetElementsByTagName=(document.getElementsByTagName) ? "true" : "false"; 
	htmlDOMdocumentElement=(document.documentElement) ? "true" : "false";
	htmlDOMdocumentAll=(document.all) ? "true":"false";
}
catch(e)
{
}
//-----------------------------------------------------
//Globals: Windows Media Play Helper Information. 
//-----------------------------------------------------
//Version 6.4 was the final version of Media Player 2,
//by now known as Windows Media Player. Version 6.4 was
//included with Windows Me, Windows 2000 and Windows XP,
//but was dropped in Windows Vista.
//-----------------------------------------------------
//There was another large revamp with version 7, with
//a new user interface and increased functionality.
//When Windows 2000 was released version 7.1 arrived.
//WMP7 came with the WMA and WMV codecs. 
//-----------------------------------------------------
var WMPVer="unknown";		//Set to WMP version string detected.
var boolHasWMP=false;		//True if either WMP v6.4 or v7+ found.
var boolHasWMP64=false;		//True if WMP v6.4 found.
var boolHasWMP7up=false;	//True if WMP v7+ (8, 9, 10, 11) found.
var objMediaPlayer=null;	//Just some temp space!
try
{
	//WMP v6.4 should be install [legacy stuff].
	objMediaPlayer=new ActiveXObject("MediaPlayer.MediaPlayer.1");
    boolHasWMP=true;
    boolHasWMP64=true;
}
catch(e) 
{
	//Trouble!
	boolHasWMP=false;
    boolHasWMP64=false;
}
try 
{
	//Try to find WMP v7+ (8, 9, 10, 11).
	objMediaPlayer=new ActiveXObject("WMPlayer.OCX.7");
    boolHasWMP=true;
	boolHasWMP7up=true;
}
catch(e) 
{
	//Trouble!
	boolHasWMP=false;
	boolHasWMP7up=false;
}
//Deal with WMP Version Information.
if(boolHasWMP7up)
{
	WMPVer=objMediaPlayer.versionInfo;
}
else if(boolHasWMP)
{
	WMPVer="6.4";
}
//Release this OBJECT.
objMediaPlayer=null;	
//Parse the WMP Version Information.
var WMPFullVersion=parseFloat(WMPVer);
var WMPMajorVersion=parseInt(WMPFullVersion);
//Keep track of the current WMP version.
var boolVersionWMP7=(WMPFullVersion == 7.0) ? "true" : "false";
var boolVersionWMP71=(WMPFullVersion == 7.1) ? "true" : "false";
var boolVersionWMP8=(WMPMajorVersion == 8) ? "true" : "false";
var boolVersionWMP9=(WMPMajorVersion == 9) ? "true" : "false";
var boolVersionWMP10=(WMPMajorVersion == 10) ? "true" : "false";
var boolVersionWMP11=(WMPMajorVersion == 11) ? "true" : "false";
var boolVersionWMP71up=(WMPFullVersion >= 7.1) ? "true" : "false";
var boolVersionWMP8up=(WMPFullVersion >= 8) ? "true" : "false";
var boolVersionWMP9up=(WMPFullVersion >= 9) ? "true" : "false";
var boolVersionWMP10up=(WMPFullVersion >= 10) ? "true" : "false";
var boolVersionWMP11up=(WMPFullVersion >= 11) ? "true" : "false";
//-----------------------------------------------------
//WMP v7+ onPlayStateChange state options array
//-----------------------------------------------------
var psArray = new Array(12);
psArray[0]="Undefined: Windows Media Player is in an undefined state.";
psArray[1]="Stopped: Playback of the current media clip is stopped."; 
psArray[2]="Paused: Playback of the current media clip is paused... resuming begins from the same location.";
psArray[3]="Playing: The current media clip is playing."; 
psArray[4]="ScanForward: The current media clip is fast forwarding.";
psArray[5]="ScanReverse: The current media clip is fast rewinding."; 
psArray[6]="Buffering: The current media clip is getting additional data from the server.";
psArray[7]="Waiting: Connection is established, however the server is not sending bits. Waiting for session to begin.";
psArray[8]="MediaEnded: Media has completed playback and is at its end.";  
psArray[9]="Transitioning: Preparing new media."; 
psArray[10]="Ready: Ready to begin playing."; 
psArray[11]="Reconnecting: Reconnecting to stream.";
//-----------------------------------------------------
//WMP v6.4 onPlayStateChange state options array
//-----------------------------------------------------
var ps64Array=new Array(9);
ps64Array[0]="mpStopped: Playback is stopped.";
ps64Array[1]="mpPaused: Playback is paused."; 
ps64Array[2]="mpPlaying: Stream is playing."; 
ps64Array[3]="mpWaiting: Waiting for stream to begin."; 
ps64Array[4]="mpScanForward: Stream is scanning forward."; 
ps64Array[5]="mpScanReverse: Stream is scanning in reverse."; 
ps64Array[6]="mpSkipForward: Skipping to next."; 
ps64Array[7]="mpSkipReverse: Skipping to previous."; 
ps64Array[8]="mpClosed: Stream is not open."; 
//-----------------------------------------------------
//Get Browser Information: Save information globally.
//-----------------------------------------------------
function GetAllBrowserInformation()
{
	try
	{
		//MS Internet Explorer??
		if(uAgent.search(/msie\s(\d+(\.?\d)*)/) != -1)
		{
			//Browser identification.
			broswerId="msie";
			//All Version information.
			browserVer=getMSIEVersion();
			browserMajorVer=getMajorVersion(browserVer);
			browserMinorVer=getMinorVersion(browserVer);
			//Browser Engine identification.
			broswerEngine="msie";
			broswerEngineVer=browserVer;
		}
		//MSN Explorer (arf!)??
		else if(uAgent.search(/msn\s(\d+(\.?\d)*)/) != -1)
		{
			//Browser identification.
			broswerId="msn";
			//All Version information.
			browserVer=uAgent.match(/msn\s(\d+(\.?\d)*)/)[1];
			browserMajorVer=getMajorVersion(browserVer);
			browserMinorVer=getMinorVersion(browserVer);
			//Browser Engine identification.
			broswerEngine="msie";
			broswerEngineVer=getMSIEVersion();
		}
		//Firefox??
		else if(uAgent.search(/firefox[\/\s](\d+([\.-]\d)*)/) != -1)
		{
			//Browser identification.
			broswerId="firefox";
			//All Version information.
			browserVer=uAgent.match(/firefox[\/\s](\d+([\.-]\d)*)/)[1];
			browserMajorVer=getMajorVersion(browserVer);
			browserMinorVer=getMinorVersion(browserVer);
			//Browser Engine identification.
			broswerEngine="gecko";
			broswerEngineVer=getGeckoVersion();
		}
		//Opera??
		else if(uAgent.search(/opera[\/\s](\d+(\.?\d)*)/) != -1)
		{
			//Browser identification.
			broswerId="opera";
			//All Version information.
			browserVer=uAgent.match(/opera[\/\s](\d+(\.?\d)*)/)[1];
			browserMajorVer=getMajorVersion(browserVer);
			browserMinorVer=getMinorVersion(browserVer);
			//Browser Engine identification.
			broswerEngine="opera";
			broswerEngineVer=browserVer;
		}
		//Netscape 7.x??
		else if(uAgent.search(/netscape\/(7\.\d*)/) != -1)
		{
			//Browser identification.
			broswerId="netscape";
			//All Version information.
			browserVer=uAgent.match(/netscape\/(7\.\d*)/)[1];
			browserMajorVer=getMajorVersion(browserVer);
			browserMinorVer=getMinorVersion(browserVer);
			//Browser Engine identification.
			broswerEngine="gecko";
			broswerEngineVer=getGeckoVersion();
		}
		//Safari??
		else if(uAgent.search(/safari\/(\d)*/) != -1)
		{
			//Browser identification.
			broswerId="safari";
			//All Version information.
			browserVer=uAgent.match(/safari\/(\d+(\.?\d*)*)/)[1];
			browserMajorVer=getMajorVersion(browserVer);
			browserMinorVer=getMinorVersion(browserVer);
			//Browser Engine identification.
			broswerEngine="khtml";
			broswerEngineVer=uAgent.match(/applewebkit\/(\d+(\.?\d*)*)/)[1];
		}
	}
	catch(e)
	{
	}
}
//-----------------------------------------------------
//Return MSIE version from the UA String.
//-----------------------------------------------------
function getMSIEVersion()
{
	return uAgent.match(/msie\s(\d+(\.?\d)*)/)[1];
}
//-----------------------------------------------------
//Return Gecko version.
//-----------------------------------------------------
function getGeckoVersion()
{
	return uAgent.match(/gecko\/([0-9]+)/)[1];
}
//-----------------------------------------------------
//Return browser's (actual) major version or -1 if bad
//version entered.
//-----------------------------------------------------
function getMajorVersion(ver) 
{
	 return (isEmpty(ver) ? -1 : (hasDot(ver) ? ver : ver.match(/(\d*)(\.\d*)*/)[1]))
}
//-----------------------------------------------------
//Return browser's (actual) minor version or -1 if bad
//version entered.
//-----------------------------------------------------
function getMinorVersion(ver)
{
	return (!isEmpty(ver) ? (!hasDot(ver) ? ver.match(/\.(\d*([-\.]\d*)*)/)[1] : 0) : -1)
}
//-----------------------------------------------------
//Is input empty?
//-----------------------------------------------------
function isEmpty(input)
{
	return (input==null || input=="")
}
//-----------------------------------------------------
//Does this string contain a dot?
//-----------------------------------------------------
function hasDot(input)
{
	return (input.search(/\./) == -1)
}
//-----------------------------------------------------
//Get Media Player Major Version Number.
//-----------------------------------------------------
function GetPlayerMajorVer()
{
    var strVer=new String(WMPFullVersion);
    s=strVer.split(".");
    return s[0];
}
//-----------------------------------------------------
//Get Media Player Minor Version Number.
//-----------------------------------------------------
function GetPlayerMinorVer()
{
    var strVer=new String(WMPFullVersion);
    s=strVer.split(".");
    if (s[1])
        return s[1];
    else
        return("unknown");
}
//-----------------------------------------------------
//Wrapper function for setting the uiMode of the WMP 
//control. Supports uiMode of none, mini & full.
//-----------------------------------------------------
function set_uiMode(uiMode)
{ 
	try
	{
		//WMP v6.4? then set ui mode related properties.
		if (boolHasWMP && !boolHasWMP7up) 
		{ 
			if (uiMode=="none") 
			{
				VideoZap.ShowControls=false;
				VideoZap.ShowTracker=false;
				VideoZap.EnableTracker=false;
				VideoZap.ShowPositionControls=false;
				VideoZap.EnablePositionControls=false;
				VideoZap.ShowStatusBar=false;
			} 
			if (uiMode=="mini") 
			{
				VideoZap.ShowControls=true;
				VideoZap.ShowTracker=false;
				VideoZap.EnableTracker=false;
				VideoZap.ShowPositionControls=false;
				VideoZap.EnablePositionControls=false;
				VideoZap.ShowStatusBar=true;
			}  
			if (uiMode=="full") 
			{
				VideoZap.ShowControls=true;
				VideoZap.ShowTracker=true;
				VideoZap.EnableTracker=true;
				VideoZap.ShowPositionControls=true;
				VideoZap.EnablePositionControls=true;
				VideoZap.ShowStatusBar=true;
			}
		}
		else if (boolHasWMP7up)
		{
			VideoZap.uiMode=uiMode;
		}
	}
	catch(e)
	{
	}
}
//-----------------------------------------------------
//Wrapper function for getting current uiMode of WMP.
//The WMP SDK says... uiMode is a string: "none" or
//or "mini" or "full".
//-----------------------------------------------------
function get_uiMode()
{
	try
	{
		//Accessing the old v6.4 properties???
		if (boolHasWMP && !boolHasWMP7up) 
		{                
			if (VideoZap.ShowControls==false &&
				VideoZap.ShowTracker==false &&
				VideoZap.EnableTracker==false && 
				VideoZap.ShowPositionControls==false && 
				VideoZap.EnablePositionControls==false)
				{
					return("none");
				}
			if (VideoZap.ShowControls==true &&
				VideoZap.ShowTracker==false && 
				VideoZap.EnableTracker==false &&
				VideoZap.ShowPositionControls==false &&
				VideoZap.EnablePositionControls==false)
				{
					return("mini");   
				}
			if (VideoZap.ShowControls==true &&
				VideoZap.ShowTracker==true &&
				VideoZap.EnableTracker==true &&
				VideoZap.ShowPositionControls==true &&
				VideoZap.EnablePositionControls==true)
				{
					return("full");   
				}
			return("unknown");
		}
		else if (boolHasWMP7up)
		{
			return(VideoZap.uiMode);
		}
	}
	catch(e)
	{
	}
}
//-----------------------------------------------------
//Using get_uiMode & set_uiMode this function cycles 
//through the UI modes of the WMP control.
//-----------------------------------------------------
function ToggleMode()
{
	try
	{
		var Mode=get_uiMode();
		if (Mode=="none") 
		{
			set_uiMode("mini");
		}
		if (Mode=="mini") 
		{
			set_uiMode("full");
		}
		if (Mode=="full")
		{
			set_uiMode("none");   
		}
	}
	catch(e)
	{
	}
}
//-----------------------------------------------------
//Returns a string describing the NewState number.
//-----------------------------------------------------
function GetPlayerState(NewState)
{
	try
	{
		if (boolHasWMP && !boolHasWMP7up)
		{
			if (NewState>=0 && NewState<=8)
			{
				return ps64Array[NewState];
			}
			else
			{
				return "mpUndefined: Windows Media Player is in an undefined state.";
			}
		}    
		else if (boolHasWMP7up)
		{
			if (NewState>=0 && NewState<=11)
			{
				return psArray[NewState];
			}
			else
			{
				return "Undefined: Windows Media Player is in an undefined state.";
			}
		}   
	}
	catch(e)
	{
	}
}



