// ###########################
// created by: Ben Weeks
// Created Date: 23th March 2006
// Company: webtechy.co.uk
//
// Modified By: Ben Weeks
// Modified Date: 15th May 2006
// Modified Comment: Made to work with other browser versions and earlier versions of Windows Media Player.
//
// Modified By: Ben Weeks
// Modified Date: 18th February 2007
// Modified Comment: Fix for Firefox to display in same window without pop-up
//
// Modified By: 
// Modified Date: 
// Modified Comment: 
//
// Version: 1.1
// ###########################

var iPopulateTimerID;

function waitThenStart()
{
	try
	{
		window.status = "Ready";
		clearInterval(iPopulateTimerID);
		document.getElementById("MediaPlayer").Play();
	}
	catch (e)
	{
	}

}

function PlayVideo(sVideoLink,iWidth,iHeight,evt) {
	try {
		// Lets get the source element
		var srcEl;
     		evt = (evt) ? evt : ((window.event) ? window.event : "")
     		if (evt) {
			srcEl = (evt.target) ? evt.target : evt.srcElement;
		}
		//alert(srcEl.parentNode);
		//alert(srcEl.parentNode.innerHTML);
		//alert(navigator.appName);

		// Get the dimensions
		if (iHeight < 1) {
			iHeight=245; }
		if (iWidth < 1) {
			iWidth = 320; }
		if (sVideoLink.substring(sVideoLink.length, sVideoLink.length - 3) == "mp3") {
			iHeight = 45; }

		if (navigator.appName == "Microsoft Internet Explorer") {
			// Then they have IE.

			// See: http://support.microsoft.com/default.aspx?kbid=279022

			if (detectPlugin('WMPlayer.OCX.7')) {
				// Then they have ActiveX enabled, and the Windows Media Player 7 correct plugin.
				sOBJECT = "<object id='MediaPlayer' width=" + iWidth + " height=" + iHeight + " autostart=1 classid='CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112' standby='Loading...' type='application/x-oleobject'><param name='Filename' value='" + sVideoLink + "'><param name='ShowControls' value='true'><param name='ShowDisplay' value='False'><param name='autostart' value='true'></object>";
				if (srcEl) {
					srcEl.outerHTML = sOBJECT;
				}
				else {
					// Just open it in another window - e.g. for FireFox, we need to pass their event into the function.
					window.open(sVideoLink);
					//location.href = sVideoLink;
				}

				//document.getElementById("MediaPlayer").Play();
				iPopulateTimerID = setInterval("waitThenStart()", 1000);
			}
			else if (detectPlugin('MediaPlayer.MediaPlayer.1')) {
				// Then they have ActiveX enabled, and an earlier version of Windows Media Player plugin.
				sOBJECT = "<object id='MediaPlayer' width=" + iWidth + " height=" + iHeight + " classid='22d6f312-b0f6-11d0-94ab-0080c74c7e95 CODEBASE=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715' standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'><param name='FileName' value='" + sVideoLink + "'><param name='autostart' VALUE='1'><param name='ShowControls' VALUE='1'></object>";
				if (srcEl) {
					srcEl.outerHTML = sOBJECT;
				}
				else {
					// Just open it in another window - e.g. for FireFox, we need to pass their event into the function.
					window.open(sVideoLink);
					//location.href = sVideoLink
				}
//				document.getElementById("MediaPlayer").Play();
				iPopulateTimerID = setInterval("waitThenStart()", 1000);
			}
			else {
				// Just open it in another window.
				window.open(sVideoLink);
				//location.href = sVideoLink
			}
		}
		else if (navigator.appName == "Netscape") {
			//Netscape code
			sOBJECT = "<Embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/windowsmedia/' filename='" + sVideoLink + "' src='" + sVideoLink + "' Name=MediaPlayer ShowControls=1 ShowDisplay=1 ShowStatusBar=1 width=" + iWidth + " height=" + iHeight + "></embed>";
			if (srcEl) {
				if (srcEl.outerHTML)
					srcEl.outerHTML = sOBJECT;
				else
					srcEl.parentNode.innerHTML = sOBJECT;
			}
			else {
				// Just open it in another window - e.g. for FireFox, we need to pass their event into the function.
				window.open(sVideoLink);
				//location.href = sVideoLink
			}
		}
		else
		{
			// Just open in another window.
			window.open(sVideoLink);
		}
	}
	catch(er) {
		//alert("An error occurred, and the video could not be played.");
		window.open(sVideoLink);
		//location.href = sVideoLink
	}
}

function detectPlugin(sPlugin)
{
	var WMP7;
	bHavePlugin = true;
	try
	{
		if(window.ActiveXObject)
		{
			new ActiveXObject(sPlugin);
		}
		else if (window.GeckoActiveXObject)
		{
			new GeckoActiveXObject(sPlugin);
		}
	}
	catch(e)
	{
		bHavePlugin = false;
	}
	return bHavePlugin;
}


