// wmp detect
var _wmpinfo = null;

function getWmpInfo()
{
	if ( _wmpinfo==null )
		_wmpinfo = buildWmpInfo();
	return _wmpinfo;
}

function buildWmpInfo()
{
	var wi = new Object();
	wi.installed = false;
	wi.version = 0;
	wi.platform = "";
	
	// set platform ( win or linux )
	var agt=navigator.userAgent.toLowerCase();
	if ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) ) wi.platform = "win";
	if (agt.indexOf("mac")!=-1) wi.platform = "mac";
	if (agt.indexOf("linux")!=-1) wi.platform = "linux";
	
	// try activexobject 7.1
	var axobj = null;
	axobj = getActiveXObject("WMPlayer.OCX.7");
	if ( axobj==null )
	{
		// try activexobject 6.4
		axobj = getActiveXObject("MediaPlayer.MediaPlayer.1")
	}

	if ( axobj!=null )
	{
		wi.installed = true;
		parseFloat(axobj.versionInfo);
		wi.version=parseFloat(axobj.versionInfo);
	}
	else if (navigator.plugins && navigator.plugins.length)
	{
		for (var i=0; i<navigator.plugins.length; i++)
		{
			if (navigator.plugins[i].name.toLowerCase().indexOf('windows media') != -1)
			{
				wi.installed=true;
				break;
			}
		}
	}
	else if (navigator.mimeTypes)
	{
      	wi.installed = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin;
	}

	return wi;
}

function getActiveXObject(id)
{
	// "try" is reserved word in NS4, use eval to hide
	var obj = null;
	if (window.ActiveXObject)
		eval ( "try { obj = new ActiveXObject(id); } catch ( e ) {}" );
	else if (window.GeckoActiveXObject)
		eval ( "try { obj = new GeckoActiveXObject(id); } catch ( e ) {}" );
	return obj;
}

function checkWmp()
{
	return ( getWmpInfo().installed && getWmpInfo().platform!="linux" );
}

function checkVersionWmp()
{
	return getWmpInfo().version;
}

// player functions

function drawVideo(src, objid, width, height, hidecontrols)
{
	if ( checkWmp() )
	{
		var h = "";
		
		if ( getWmpInfo().version>=7 )
		{
			h =
			'<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" ' +
			'id="' + objid + '" ' +
			'width="' + width + '" ' +
			'height="' + height + '"> ' +
			'<param name="url" value="' + src + '"> ' +
			'<param name="AutoStart" VALUE="True"> ' +
			'<param name="uiMode" value="' + ( hidecontrols ? "none" : "full" ) + '"> ' +
			'<param name="stretchToFit" value="True"> ' +
			'</object>';
		}
		else
		{
			h =
			'<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ' +
			'id="' + objid + '" ' +
			'width="' + width + '" ' +
			'height="' + height + '"> ' +
			'<param name="Filename" value="' + src + '"> ' +
			'<param name="AutoStart" value="1"> ' +
			'<param name="ShowControls" value="' + ( hidecontrols ? "0" : "1" ) + '"> ' +
			'<param name="ShowDisplay" value="0"> ' +
			'<param name="ShowStatusBar" value="0"> ' +
			'<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" ' +
			'	name="' + objid + '" ' +
			'	width="' + width + '" ' +
			'	height="' + height + '" ' +
			'	filename="' + src + '" ' +
			'	autostart="1" ' +
                        '       fullscreen="1" ' +
			'	showcontrols="' + ( hidecontrols ? "0" : "1" ) + '" ' +
                        '       displaysize=4 ' +
                        '       autosize=-1 ' + 
			'	showdisplay="0" ' +
			'	showstatusbar="0"></embed> ' +
			'</object>';
		}

		document.write ( h );
	}
	else
	{
		drawWmpDownload(src);
	}
}
function drawVideoNoStretch(src, objid, width, height, hidecontrols)
{
	if ( checkWmp() )
	{
		var h = "";
		
		if ( getWmpInfo().version>=7 )
		{
			h =
			'<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" ' +
			'id="' + objid + '" ' +
			'width="' + width + '" ' +
			'height="' + height + '"> ' +
			'<param name="url" value="' + src + '"> ' +
			'<param name="AutoStart" VALUE="True"> ' +
			'<param name="uiMode" value="' + ( hidecontrols ? "none" : "full" ) + '"> ' +
			'<param name="stretchToFit" value="False"> ' +
			'</object>';
		}
		else
		{
			h =
			'<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ' +
			'id="' + objid + '" ' +
			'width="' + width + '" ' +
			'height="' + height + '"> ' +
			'<param name="Filename" value="' + src + '"> ' +
			'<param name="AutoStart" value="1"> ' +
			'<param name="ShowControls" value="' + ( hidecontrols ? "0" : "1" ) + '"> ' +
			'<param name="ShowDisplay" value="0"> ' +
			'<param name="ShowStatusBar" value="0"> ' +
			'<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" ' +
			'	name="' + objid + '" ' +
			'	width="' + width + '" ' +
			'	height="' + height + '" ' +
			'	filename="' + src + '" ' +
			'	autostart="1" ' +
                        '       fullscreen="-1" ' +
			'	showcontrols="' + ( hidecontrols ? "0" : "1" ) + '" ' +
                        '       displaysize=0 ' +
                        '       autosize=-1 ' + 
			'	showdisplay="0" ' +
			'	showstatusbar="0"></embed> ' +
			'</object>';
		}

		document.write ( h );
	}
	else
	{
		drawWmpDownload(src);
	}
}
function drawAudio(src, objid, hidecontrols)
{
width=450;
height=45;
	if ( checkWmp() )
	{
		var h = "";
		
		if ( getWmpInfo().version>=7 )
		{
			h =
			'<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" ' +
			'id="' + objid + '" ' +
			'width="' + width + '" ' +
			'height="' + height + '"> ' +
			'<param name="url" value="' + src + '"> ' +
			'<param name="AutoStart" VALUE="True"> ' +
			'<param name="uiMode" value="' + ( hidecontrols ? "none" : "full" ) + '"> ' +
			'<param name="stretchToFit" value="True"> ' +
			'</object>';
		}
		else
		{
			h =
			'<object classid="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" ' +
			'id="' + objid + '" ' +
			'width="' + width + '" ' +
			'height="' + height + '"> ' +
			'<param name="Filename" value="' + src + '"> ' +
			'<param name="AutoStart" value="1"> ' +
			'<param name="ShowControls" value="' + ( hidecontrols ? "0" : "1" ) + '"> ' +
			'<param name="ShowDisplay" value="0"> ' +
			'<param name="ShowStatusBar" value="0"> ' +
			'<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/" ' +
			'	name="' + objid + '" ' +
			'	width="' + width + '" ' +
			'	height="' + height + '" ' +
			'	filename="' + src + '" ' +
			'	autostart="1" ' +
                        '       fullscreen="1" ' +
			'	showcontrols="' + ( hidecontrols ? "0" : "1" ) + '" ' +
                        '       displaysize=4 ' +
                        '       autosize=-1 ' + 
			'	showdisplay="0" ' +
			'	showstatusbar="0"></embed> ' +
			'</object>';
		}

		document.write ( h );
	}
	else
	{
		drawWmpDownload(src);
	}
}
function fullscreenVideo( objid )
{
	var objref = getVideoObjRef(objid);
	if ( objref.playState == 3 && getWmpInfo().version>=7 )
        {
		objref.fullscreen = true;
               
        }
}

function getVideoObjRef( objid )
{
	var objref = document[objid];
	if ( document.getElementById )
		objref = document.getElementById(objid);
	return objref;
}

function drawWmpDownload(url)
{
	document.write("<span class='lighttxtbigtext2'><b>Attenzione</b>.<br>Windows Media Player non &egrave; installato.<br>");
	
	if ( getWmpInfo().platform == "linux" )
	{
		document.write("<br /><a href='" + url + "'><font color='yellow'>Clicca qui</font></a><br />" +
					"per visualizzare il video<br />" +
					"con un player differente.");
	}
	else
	{
		document.write("Clicca qui sotto per installare<br>gratuitamente Windows Media Player.<br><br>");
		document.write("<a class=\"lighttxttitle2\" href='http://www.microsoft.com/windows/windowsmedia/' target='_new'>Scarica Windows Media Player</a></span>");
	}
	
	
}

// test functions

function testWmp()
{

		alert ( "Windows Media Player rilevato: " + checkVersionWmp());

}