/*
Funciones necesarias para la carga del reproductor 
Windows Media Player en el player de CanalGV
*/

// Create an ActiveX/GeckoActiveX constructor
function AXO(id)
{
	var error; var control = null;
	try {
		if (window.ActiveXObject && navigator.userAgent.indexOf('Win') != -1) control = new ActiveXObject(id);
		else if (gkoaxwma) control = new GeckoActiveXObject(id);
	}
	catch (error) {}
	return control;
}

function createWMP()
{
	// Set some base values
	var windowsmedia=new Object();
	windowsmedia.installed=false;
	windowsmedia.version='0';
	
	// Gecko: tiene plugin de ActiveX?
	var gkoaxwma=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) { 
			gkoaxwma=true; break; 
		} 
	  } 
	}
	if (window.ActiveXObject || gkoaxwma) {
		try
		{
			oWMP=new AXO('WMPlayer.OCX.7');
			if (oWMP)
			{
				windowsmedia.installed=true;
				// A wierd bug in the Gecko ActiveX plug-in will return
				// undefined at the first call, but the correct value on the second.
				// This "fix" doesn't seem to hurt IE at all.
				parseFloat(oWMP.versionInfo);
				windowsmedia.version=parseFloat(oWMP.versionInfo);
				if(isNaN(windowsmedia.version)) windowsmedia.version = 6;
			}
		}
		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)
			{
				//alert(navigator.plugins[x].name+" - "+navigator.plugins[x].description);
				windowsmedia.installed=true;
				//nunca saldrá el mensaje. Imposible detectar versión del plugin
				windowsmedia.version=9;
				break;
			}
		}
	}
	return windowsmedia;
}

function showPluginWMP(WMP,URL,mess1,mess2)
{
	if (!WMP.installed || WMP.version < 8)
		document.write('<p class="texto">'+mess1+' <a href="'+URL+'" target="_blank">'+mess2+'</a></p>');
}

function showWMP(WMP,URL,File,mess1,width,height,BGcolor)
{
  if (navigator.appName == "Microsoft Internet Explorer"){ 
    // Windows Media Player 7 Code o Superior
	if (WMP.version >= 7) {
		 //Escibimos el objeto para IE
		 document.write ('<OBJECT ID=wmp ');
		 document.write ('CLASSID=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6 ');
		 document.write ('CODEBASE='+URL+' ');
		 document.write ('standby='+mess1+' ');
		 document.write ('WIDTH='+width+' ');
		 document.write ('HEIGHT='+height+' ');
		 document.write ('TYPE="application/x-oleobject">');		 
		 document.write ('<PARAM NAME="url" VALUE="'+File+'">');
		 //document.write ('<PARAM NAME="AutoSize" VALUE="<cfoutput>#int_AutoSize#</cfoutput>">');
		 document.write ('<PARAM NAME="AutoStart" VALUE="true">');
		 document.write ('<param name="Loop" value="0">');		 
		 //document.write ('<PARAM NAME="uiMode" VALUE="full">');
		 document.write ('<param name="AnimationAtStart" value="1">');
		 document.write ('<PARAM NAME="DisplayBackColor" VALUE="'+BGcolor+'">');
		 document.write ('<param name="ShowControls" value="1">');		 		 		 
		 document.write ('<param name="ShowDisplay" value="1">');
		 document.write ('<param name="ShowStatusBar" value="1">');
		 document.write ('<param name="TransparentAtStart" value="1">');		 
		 document.write ('</OBJECT>');
		 //Propiedades del objeto
		 wmp.enableContextMenu = true;
	// Windows Media Player 6.4 Code
	}else{
		 //Escribimos el objeto para IE
		 document.write ('<OBJECT ID=wmp ');
		 document.write ('CLASSID=CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95 ');
		 //http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab##Version=6,4,5,715
		 document.write ('CODEBASE='+URL+' ');
		 document.write ('standby='+mess1+' ');
		 document.write ('WIDTH='+width+' ');
		 document.write ('HEIGHT='+height+' ');
		 document.write ('TYPE="application/x-oleobject">');
		 document.write ('<PARAM NAME="FileName" VALUE="'+File+'">');
		 //document.write ('<PARAM NAME="AutoSize" VALUE="<cfoutput>#int_AutoSize#</cfoutput>">');
		 document.write ('<PARAM NAME="AutoStart" VALUE="true">');
		 document.write ('<param name="Loop" value="0">');		 
		 //document.write ('<PARAM NAME="uiMode" VALUE="full">');
		 document.write ('<param name="AnimationAtStart" value="1">');
		 document.write ('<PARAM NAME="DisplayBackColor" VALUE="'+BGcolor+'">');
		 document.write ('<param name="ShowControls" value="1">');		 		 		 
		 document.write ('<param name="ShowDisplay" value="1">');
		 document.write ('<param name="ShowStatusBar" value="1">');
		 document.write ('<param name="TransparentAtStart" value="1">');
		 document.write ('</OBJECT>');
		 //Propiedades del objeto
		 wmp.enableContextMenu = true;
		 /*var ls_test = '<cfoutput>#int_AutoSize#</cfoutput>';
		 wmp.autosize = (ls_test == '')? 1: eval(ls_test);
		 wmp.autostart = true;
		 wmp.AllowChangeDisplaySize = true;
		 wmp.TransparentAtStart = true;
	 	 wmp.DisplaySize = 0;
		 wmp.style.visibility = "visible";
		 wmp.ShowPositionControls = false;				
		 wmp.ShowDisplay = true;		 
		 wmp.ShowAudioControls = true;
		 wmp.ShowControls = true;
		 wmp.VideoBorderWidth = 0;
		 wmp.Mute = 0;*/
	}
  }else{ 
	//Escribimos el objeto para resto navegadores
	var ls_html = '<embed name="wmp" ';
		ls_html += 'pluginspage='+URL+' ';
		ls_html += 'WIDTH='+width+' ';
		ls_html += 'HEIGHT='+height+' ';
		ls_html += 'TYPE="application/x-mplayer2" ';
		ls_html += 'SRC="'+File+'" ';
		//ls_html += 'autosize=1 ';		
		ls_html += 'autostart=true ';
		ls_html += 'showcontrols=1 ';
		ls_html += 'enablecontextmenu=0 ';		
		//ls_html += 'mute=1 ';
		ls_html += '></embed>';
		document.write(ls_html);
  }	
}

