var axPlayer=false;
// Browser detection
var agt = navigator.userAgent.toLowerCase();

// Browser version
// Warning: On IE5, these return 4, we are using is_ie5up to detect IE5.
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

// Note: Opera and WebTV spoof Navigator.  We do strict client detection.
// If you want to allow spoofing, take out the tests for opera and webtv.
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
			&& (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
			&& (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));

var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);
var is_fireFox = (agt.indexOf('firefox') != -1);
var is_opera = (agt.indexOf('opera') != -1);

var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up  = (is_ie && (is_major >= 4));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);

// Platform detection
var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_mac    = (agt.indexOf("mac")!=-1);

var os;
var browser;
var wmplayer;
var tech = "wmp";


if (is_win==true){
	os="win";
} else if (is_mac==true){
	os="mac";
} else {
	os="other";
};

if (is_ie5_5up==true){
	browser="ie";
} else if (is_gecko==true ){
	browser="nn";
} else if (is_nav6up==true){
	broswer="nn";
} else if (!is_nav6up && !is_gecko){
	browser="other";
};

if (browser == "nn" && is_fireFox){
	browser = "ff";
};
if (is_opera){ 
	browser = "op";
};

if (is_win==true){
	os="win";
	tech = "wmp";
} else if (is_mac==true){
	os="mac";
	tech = "flip4mac";
} else {
	os="other";
	tech = "vlc";
};


function checkFlip4Mac() {
	var haveFlip4Mac = false;
	for (var i = 0; i < navigator.plugins.length; i++) {
		if (navigator.plugins[i].name.indexOf("Flip4Mac") != -1) {
			haveFlip4Mac = true; 
			break;
		}
	}
	return haveFlip4Mac;
} 

function detectWMP(){
	var wmpInfo = {
		installed: false,
		scriptable: false,
		type: null,
		versionInfo: null
	};
	//var wmp64 = "MediaPlayer.MediaPlayer.1";
	var wmp7 = "WMPlayer.OCX";
	if((window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1) ) {
		wmpInfo.type = "ActiveX";
		var player = createActiveXObject(wmp7);
		if(player) {
			wmpInfo.installed = true;
			wmpInfo.scriptable = true;
			wmpInfo.versionInfo = player.versionInfo;		
		}
	} else if(navigator.mimeTypes) {
		wmpInfo.type = "NetscapePlugin";
		var player = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin;
		if(player) {	
			wmpInfo.installed = true;
			wmpInfo.scriptable = false;
			wmpInfo.versionInfo = "PluginVersion";
			
			for( var i in  navigator.plugins )
			{
				var n = navigator.plugins[i].name;
				if ( n != null && n.indexOf("Windows Media") >= 0 && n.indexOf("Microsoft") >= 0 )
				{
					wmpInfo.scriptable = true;
					break;
				}
			}
			
		};
	};
	return wmpInfo;
};

function createActiveXObject(id){
	var error;
	var control = null;

	try  {
		if (window.ActiveXObject)    {
			control = new ActiveXObject(id);
		}  else if (window.GeckoActiveXObject)    {
			control = new GeckoActiveXObject(id);
		}
	}  catch (error)  {
		;
	};
	return control;
};


function installAxFF15() { 
	xpi={'Mozilla Firefox 1.5 ActiveX Plug-in':'http://www.iol.ie/~locka/mozilla/mozactivex-ff-15.xpi'}; InstallTrigger.install(xpi); 
};

function installAxFF() { goURL("http://www.iol.ie/~locka/mozilla/plugin.htm");}; 

function getPlayer(DivId, playerUrl, playerWidth, playerHeight){
	var div = document.getElementById(DivId);
	if(!is_mac) {
		var detectionResults = detectWMP();
		if (detectionResults.installed) {			
			axPlayer=true;
			div.innerHTML=getHTMLForActiveX(playerUrl, playerWidth, playerHeight, detectionResults);
			
		} else  {
			axPlayer=false;
			var buff="Ce site privil�gie l'utilisation du player Windows Media, en mode ActiveX.\n\n";
			installStr= detectionResults.installed ? 'est install�' : 'n\'est pas install�';
			buff+="D�tection  : " + detectionResults.type + " " + installStr + "\n\n";
			//buff+="Pour installer le composant, utilisez la rubrique d'aide.La proc�dure et les ressources d'installation y est disponible.\n\n Si vous desirez �tre redirig� vers la proc�dure d'installation cliquez sur OK.";
			//alert(buff);
			if ( browser == 'ff') {
				div.innerHTML='<strong>Windows Media Player Plug-in pour Firefox est n�cessaire.</strong><br>';
				div.innerHTML+='<a href="http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx" target="_blank">Cliquez ici pour t�l�charger le plugin.</a>';
				div.innerHTML+=getHTMLForActiveX(playerUrl, playerWidth, playerHeight);
			};
		};
	} else {
		if(!checkFlip4Mac()) {
			axPlayer=false;
			div.innerHTML = "<div style='position:relative;left:15px;top:120px;z-index:10'><a href='http://www.flip4mac.com/wmv_download.htm' target='_blank'>";
			div.innerHTML += "Pour lire ce m�dia, veuillez t�l�charger Flip4Mac.</a></div>";
			
		} else {
			axPlayer=true;
			div.innerHTML = getHTMLFlip4Mac(playerUrl, playerWidth, playerHeight, detectionResults);
		}
	}
};

function getHTMvlc(url) {
		var LineEnd="\n";
		var t = "<embed id='player' name='player' pluginspage='http://www.videolan.org' type='application/x-vlc-plugin' progid='VideoLAN.VLCPlugin.2' width='387' height='290' MRL='"+url+"'></embed>";
		//alert(t);
		return t;
};

function getHTMLelse(movie) {
	if(movie!=undefined) {
		var LineEnd="\n";
		var t = "<EMBED type='application/x-mplayer2' name='player' id='player'  pluginspage='http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=media&sba=plugin' " + LineEnd ;
		t += " width='387' height='290' " + LineEnd;
		t += " src='"+movie+"' " + LineEnd;
		t += " autoStart='true' stretchToFit='true' AutoSize='false' enableContextMenu='false' ShowControls='true' ShowAudioControls='true' PlayCount='999' ShowTracker='true' uiMode='true' ></EMBED>" + LineEnd;
		//alert(t);
		return t;
	};
};

function getHTMLForActiveX(playerUrl, playerWidth, playerHeight, dResult) {
	var clid;
	var params = "";
	var LineEnd="\n";

	clid = "CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6";
	cbase = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=7,0,0,1954";
	params = " <param name=\"stretchToFit\" VALUE=\"true\">" +LineEnd;
	params += " <param name=\"uiMode\" VALUE=\"full\">" + LineEnd;
	params += " <param name=\"url\" VALUE=\"\">" + LineEnd;
	
	if(browser=="ff" && dResult.scriptable)
	{
		var t="<object id=\"player\" " + LineEnd +
		" type=\"application/x-ms-wmp\"" + LineEnd +
		" height=\""+playerHeight+"\" " + LineEnd +
		" width=\""+playerWidth+"\">" + LineEnd +
		" <param name=\"uiMode\" value=\"full\" />" + LineEnd +
		" <param name=\"Mute\" value=\"false\" />" + LineEnd +
		" <param name=\"volume\" value=\"100\" />" + LineEnd +
		" <param name=\"autoStart\" value=\"true\" />" + LineEnd +
		" <param name=\"URL\" value=\""+playerUrl+"\" /> " + LineEnd +
		" <param name=\"StretchToFit\" value=\"True\" />" + LineEnd +
		" </object>";
	
	}
	else
	{
		var t='';
		
		if(browser=="ff")
		{
			t+='<div id="plugindiv"><div><strong style="background-color:yellow">Windows Media Player Plug-in pour Firefox est recommand� afin de voir la vid�o dans des conditions optimales.</strong><br>';
			t+='<a href="http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx" target="_blank" style="color:blue;text-decoration:underline">Cliquez ici pour t�l�charger le plugin.</a></div></div>';
		}
		
		t+= "<object ID='player' width='"+playerWidth+"' height='"+playerHeight+"' " + LineEnd +
		" classid=\""+clid+"\" " + LineEnd +
		" codebase= " + cbase + LineEnd +
		" standby=\"Loading Microsoft Windows Media Player components...\"" +
		" type=\"application/x-oleobject\">" + LineEnd +
		" <param name=\"uiMode\" value=\"full\" />" + LineEnd +
		" <param name=\"Mute\" value=\"0\" />" + LineEnd +
		" <param name=\"volume\" value=\"100\" />" + LineEnd +
		" <param name=\"autoStart\" value=\"true\" />" + LineEnd +
		" <param name=\"URL\" value=\""+playerUrl+"\" /> " + LineEnd +
		" <param name=\"StretchToFit\" value=\"true\" />" + LineEnd +
		" <EMBED TYPE=\"application/x-mplayer2\" " + LineEnd +
		" SRC=\""+playerUrl+"\"" + LineEnd +
		" NAME=\"player\"" + LineEnd +
		" ID=\"player\"" + LineEnd +
		" WIDTH=\""+playerWidth+"\"" + LineEnd +
		" HEIGHT=\""+playerHeight+"\"" + LineEnd +
		" AllowChangeDisplaySize=\"true\"" + LineEnd +
		" DisplaySize = \"4\"" + LineEnd +
		" AutoSize=\"0\"" + LineEnd +
		" ShowControls=\"1\"" + LineEnd +
		" Mute=\"0\"" + LineEnd +
		" Volume=\"100\">" + LineEnd +
	" </EMBED></object>";
	}

return t;
};

function getHTMLFlip4Mac(playerUrl, playerWidth, playerHeight) {
	var clid;
	var params = "";
	var LineEnd="\n";

	clid = "CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6";
	cbase = "http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=7,0,0,1954";
	params = " <param name=\"stretchToFit\" VALUE=\"true\">" +LineEnd;
	params += " <param name=\"uiMode\" VALUE=\"full\">" + LineEnd;
	params += " <param name=\"url\" VALUE=\"\">" + LineEnd;

var t = "<object ID='player' width='"+playerWidth+"' height='"+playerHeight+"' " + LineEnd +
	" classid=\""+clid+"\" " + LineEnd +
	" codebase= " + cbase + LineEnd +
	" standby=\"Loading Microsoft Windows Media Player components...\"" +
	" type=\"application/x-oleobject\">" + LineEnd +
	" <param name=\"ShowControls\" value=\"1\">" + LineEnd +
	" <param name=\"EnableContextMenu\" value=\"false\">" + LineEnd +
	" <param name='AutoStart' value='true'>" + LineEnd +
	" <param name='stretchToFit' value='true'>" + LineEnd +
	" <param name='src' value='"+playerUrl+"'>" + LineEnd + 
	" <param name='PlayCount' value='999'>" + LineEnd + 
	" <param name='volume' value='100'>" + LineEnd +
	" <param name='AutoSize' value='true'>" + LineEnd +
	" <param name='WindowlessVideo' value='true'>" + LineEnd +
	" <param name='ShowStatusBar' value='true'>" + LineEnd + params;
	t += "<EMBED type='application/x-mplayer2' name='player' id='player'  pluginspage='http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=media&sba=plugin' " + LineEnd ;
	t += " width='"+playerWidth+"' height='"+playerHeight+"' " + LineEnd;
	t += " autoStart='true' stretchToFit='true' SRC='"+playerUrl+"' AutoSize='false' enableContextMenu='false' ShowControls='1' ShowAudioControls='true' ShowTracker='true' uiMode='full' ></EMBED>" + LineEnd +"</object>";
		return t;
}
