
var curDiv;

//determine if the user has wmp installed
var wm=new Object();
wm.installed=false;
wm.version='0.0';
var gecko=false;
var WMPisActiveX = false;
if (navigator.plugins && navigator.plugins.length) { for (x=0; x<navigator.plugins.length; x++) { if (navigator.plugins[x].name.indexOf('ActiveX') != -1 && window.GeckoActiveXObject) { gecko=true; break; } } }

// Create an ActiveX/GeckoActiveX constructor
function detectActiveX(id)
{
	var error; var control = null;
	try {
		if (window.ActiveXObject && navigator.userAgent.indexOf('Win') != -1) control = new ActiveXObject(id);
		else if (gecko) control = new GeckoActiveXObject(id);
	}
	catch (error) {}
	return control;
}

if (window.ActiveXObject || gecko)
{
	try
	{
		activeX=new detectActiveX('WMPlayer.OCX.7');
		if (activeX)
		{
			wm.installed=true;

			parseFloat(activeX.versionInfo);

			wm.version=parseFloat(activeX.versionInfo);
			if (wm.version.toString().length == 1) wm.version+='.0';
		}
	}
	catch(e) {}
}
else if (navigator.plugins && navigator.plugins.length)
{
	for (x=0; x<navigator.plugins.length; x++)
	{
		if (navigator.plugins[x].name.indexOf('Windows Media') != -1)
		{
			wm.installed=true;
			break;
		}
	}
}





function renderWMP()
{
	var sCR = "";
	if (wm.installed && isIE && isWin)//vars from flash.js
	{	
		WMPisActiveX = true;
		//activex installation
		sCR="<OBJECT id=\"Player2\" classid=CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 width=100% height=100%>\n";
		sCR+="<PARAM NAME=\"AutoSize\" VALUE=\"1\">\n";
		sCR+="<PARAM NAME=\"AutoStart\" VALUE=\"1\">\n";
		sCR+="<PARAM NAME=\"AnimationAtStart\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"DisplayMode\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"DisplaySize\" VALUE=\"4\">\n";
		sCR+="<PARAM NAME=\"ShowControls\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"Filename\" VALUE=\"\">\n";
		sCR+="<PARAM NAME=\"PlayCount\" VALUE=\"1\">\n";
		sCR+="<PARAM NAME=\"PreviewMode\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"StretchToFit\" VALUE=\"1\">\n";
		sCR+="<PARAM NAME=\"UIMode\" VALUE=\"none\">\n";
		sCR+="<PARAM NAME=\"ShowStatusBar\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"ShowTracker\" VALUE=\"1\">\n";
		sCR+="<PARAM NAME=\"TransparentAtStart\" VALUE=\"1\">\n";
		sCR+="<PARAM NAME=\"VideoBorderWidth\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"VideoBorderColor\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"VideoBorder3D\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"WindowlessVideo\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"ClickToPlay\" VALUE=\"0\">\n";
		sCR+="<PARAM NAME=\"SendMouseClickEvents\" VALUE=\"1\">\n";
		sCR+="<param name=\"CursorType\" value=\"1\">\n";
		sCR+="<PARAM NAME=\"src\" VALUE=\"\">\n";
		sCR+="<PARAM NAME=\"URL\" VALUE=\"\">\n";
		sCR+="</OBJECT>";
		
		
	}
	else if (wm.installed)
	{
		WMPisActiveX = false;
		sCR="";
	}
	
	document.write(sCR);
}

function startEmbedWMP(divId, url, w, h)
{
	curDiv = divId;
	//alert("start " + divId + ":" + url + ":" + w + ":" + h);
	var playercode = '<OBJECT ID="Player2" WIDTH="100%" HEIGHT="100%" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715" TYPE="application/x-oleobject" STANDBY="Loading Microsoft Windows Media Player components..." CLASSID="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6">' +
	'<param name="uiMode" value="mini" />' +
	'<param name="StretchToFit" value="true" />' +
	'<param name="Autostart" value="1" />' +
	'<param name="Loop" value="False" />' +
	'<param name="url" value="' + url + '" />' +
	'<embed id="player" width="100%" height="100%" uiMode="mini" src="' + url + '" type="video/x-ms-asf-plugin" showstatusbar="0" showdisplay="0" stretchtofit="true" autorewind="0" animationstart="0" autostart="1" />' +
	'</OBJECT>';
	//'<a href=# onclick=closeEmbedWMP()>CLOSE</a>';
	document.getElementById(divId).innerHTML = playercode;
	document.getElementById(divId).style.visibility = "visible"
	document.getElementById(divId).style.display = "block";
}

function endEmbedWMP(divId)
{	
	document.getElementById(divId).url = "";		
	document.getElementById(divId).innerHTML = "";
	document.getElementById(divId).style.display = "none";	
}

function closeEmbedWMP()
{
	endEmbedWMP(curDiv);
	sendEvent("playbackDone");
}