// Fecha:     20031210
// Copyright:   (c) 2003, Mundinteractivos - El Mundo

// 20050715 : Se habilita soporte para version 8 de flash (damos margen hasta la 9)
// 20050512 : Se utiliza el nombre del swf para identificar del objeto flash
// 20050319 : Se incluyen funciones para el sky deslizable y click en gifs de las creatividades
// 20050310 : Mejorada la deteccion de las versiones flash 5,6 y 7 en explorer
// 20050124 : Elimino la segmentacion para navegadores khtml
// 20050114 : Paso de parametro al tag del flash en EscribreGraficoFlash 
// con la url al directorio que contine en flash que se inserta
// 20040401 : Aniadida justificacion en funcion EscribeGraficoFlash
//	      y modificada la salida en caso de no disponer de flash

//Notifica la inclusion o no del codigo
var JSIncludePubli = true;

var JSflashVersion = 0;
var JSflashVersion_DONTKNOW = -1;

function getFlashVersion() {
	var agent = navigator.userAgent.toLowerCase(); 

   // NS3 needs JSflashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      JSflashVersion = 0;
   }
   
	// NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var flashPlugin = navigator.plugins['Shockwave Flash'];
		if (typeof flashPlugin == 'object') { 
			if (flashPlugin.description.indexOf('9.') != -1) JSflashVersion = 9;
			else if (flashPlugin.description.indexOf('8.') != -1) JSflashVersion = 8;
			else if (flashPlugin.description.indexOf('7.') != -1) JSflashVersion = 7;
			else if (flashPlugin.description.indexOf('6.') != -1) JSflashVersion = 6;
			else if (flashPlugin.description.indexOf('5.') != -1) JSflashVersion = 5;
			else if (flashPlugin.description.indexOf('4.') != -1) JSflashVersion = 4;
			else if (flashPlugin.description.indexOf('3.') != -1) JSflashVersion = 3;
		}
	}

	// IE4+ Win32:  attempt to create an ActiveX object using VBScript
	else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
	   document.write('<scr' + 'ipt language="VBScript"\> \n');
		document.write('on error resume next \n');
		document.write('dim obFlash \n');
		document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.9") \n');
		document.write('if IsObject(obFlash) then \n');
		document.write('JSflashVersion = 9 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.8") end if \n');
		document.write('if JSflashVersion < 9 and IsObject(obFlash) then \n');
		document.write('JSflashVersion = 8 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") end if \n');
		document.write('if JSflashVersion < 8 and IsObject(obFlash) then \n');
		document.write('JSflashVersion = 7 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
		document.write('if JSflashVersion < 7 and IsObject(obFlash) then \n');
		document.write('JSflashVersion = 6 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
		document.write('if JSflashVersion < 6 and IsObject(obFlash) then \n');
		document.write('JSflashVersion = 5 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
		document.write('if JSflashVersion < 5 and IsObject(obFlash) then \n');
		document.write('JSflashVersion = 4 \n');
		document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
		document.write('if JSflashVersion < 4 and IsObject(obFlash) then \n');
		document.write('JSflashVersion = 3 \n');
		document.write('end if \n');
		document.write('if JSFlashVersion > 4 then \n');
		document.write('Set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash") \n');
		document.write('JSFlashVersion = Left(Hex(obFlash.FlashVersion),1) \n');
		document.write('end if \n');
		document.write('</scr' + 'ipt\> \n');
  }
		
	// WebTV 2.5 supports flash 3
	else if (agent.indexOf("webtv/2.5") != -1) JSflashVersion = 3;

	// older WebTV supports flash 2
	else if (agent.indexOf("webtv") != -1) JSflashVersion = 2;

	// Can't detect in all other cases
	else {
		JSflashVersion = JSflashVersion_DONTKNOW;
	}

	return JSflashVersion;
}

function flash_id(cadena)
// devuelve un identificador para el objeto flash basado en el nombre del swf.
//nos quedamos con el nombre del swf sin path ni extension
{
	var patron = /.*\/([\w-]+)\.swf$/i;
	if (patron.test(cadena))
	{
		return (RegExp.$1);
	}
	return "PeliculaFlash";
}

// Abre una nueva ventana cada vez que se pide
function abre_ventana_foto_grande(url,params)
{
	var wname = Math.round(Math.random() * 100000000);
	window.open(url,wname,params);
}



//Escritura bloque flash para publicidad
//archivoswf: url al archivo swf
//cadenaclicktag: parametros  que se le pasa al swf (cadena completa desde ? incluido)
//ancho: dimension x
//alto: dimension y
//wmode:    window, opaque, transparent  Uno de ellos
function EscribeBloquePublicidadFlash(archivoswf, cadenaclicktag, ancho, alto, wmode)
{
	var idflash = flash_id(archivoswf);
	var cadena = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" ' + 'width="' + ancho + '" height="' + alto + '" id="' + idflash + '">\n';
	cadena = cadena + '<param name="movie" value="' + archivoswf + cadenaclicktag + '" />\n'; 
	cadena = cadena + '<param name="wmode" value="' + wmode +'" />\n';
	cadena = cadena + '<param name="quality" value="high" />\n';
	cadena = cadena + '<param name="menu" value="false" />\n';
	cadena = cadena + '<embed wmode="' + wmode + '" src="' + archivoswf + cadenaclicktag + '" quality="high" menu="false" width="' + ancho + '" height="' + alto + '" name="' + idflash + '" type="application/x-shockwave-flash" ' + ' pluginspage="http://www.macromedia.com/go/getflashplayer">\n';
	cadena = cadena + '</embed>\n';
	cadena = cadena + '</object>\n';
	document.write(cadena);
}



//Escritura bloque flash para graficos
//archivoswf: url al archivo swf
//cadenaclicktag: parametros  que se le pasa al swf (cadena completa desde ? incluido)
//ancho: dimension x
//alto: dimension y
//wmode:    window (opaco) transparent (transparente)
//version: version para la que ha sido creado el swf
//justificacion : alineacion del grafico : right, left, center
function EscribeGraficoFlash(archivoswf, cadenaclicktag, ancho, alto, wmode,version,justificacion)
{

	var LocalVersion = getFlashVersion();
	var cadena;
	if (LocalVersion > 0)
	{
		//Si no se dispone de la version adecuada mostramos un flash version 1, respetando las dimensiones 
		if (LocalVersion < version)
		{
			archivoswf = "http://cache.elmundo.es/banners/publicidad/noflashc.swf";
			cadenaclicktag = "?clickTag=http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
			//ancho = 300;
			//alto = 300;
		}
		//Escribimos el bloque
		//Reparamos la url al swf si es www.elmundo.es o elmundodeporte
		 archivoswf = archivoswf.replace(/http:\/\/www\.elmundo\.es/i,"http:\/\/estaticos\.elmundo\.es");
		archivoswf = archivoswf.replace(/http:\/\/elmundodeporte\.elmundo\.es/i,"http:\/\/estaticos\.elmundo\.es");
		//Extraemos la url del swf
		var urlflash = "";
		var re_url = /(http:\/\/.*)\/[\w-]+\.swf$/i;
		
		if ( re_url.test(archivoswf) )
		{
			urlflash = RegExp.$1;
		}
		var idflash = flash_id(archivoswf);
		cadena= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ' + 
			'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab" ' +
			'width="' + ancho +
			'" height="' + alto +
			'" align="' + justificacion +
			'" id="' + idflash + '">\n';
		cadena = cadena + '<param name="movie" value="' + archivoswf + cadenaclicktag + '" />\n'; 
		cadena = cadena + '<param name="wmode" value="' + wmode + '" />\n';
		cadena = cadena + '<param name="quality" value="high" />\n';
		cadena = cadena + '<param name="menu" value="false" />\n';
		cadena = cadena + '<param name="flashvars" value="urldirectorioswf=' + urlflash + '" />\n';
		cadena = cadena + '<embed wmode="' + wmode + '" src="' + archivoswf + cadenaclicktag + '" quality="high" menu="false" width="' + ancho + '" height="' + alto + '" align="' + justificacion + '" name="' + idflash + '" flashvars="urldirectorioswf=' + urlflash + '" type="application/x-shockwave-flash" ' + ' pluginspage="http://www.macromedia.com/go/getflashplayer">\n';
		cadena = cadena + '</embed>\n';
		cadena = cadena + '</object>\n';
		document.write(cadena);
	}
	else
	{
		cadena = '<table cellspacing="0" cellpadding="10" bgcolor="eeeeee" border="0" width="'+ ancho +'" height="'+ alto +'" align="'+ justificacion +'"><tr><td align="center"><a href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Instale el plug-in de Flash para ver correctamente este contenido</a></td></tr></table>\n'
		document.write(cadena);
	}
}

//Funcion para el click del anunciante
function clickAnunciante(url)
{
	window.open(url);
}

//Codigo para creatividad de 240x500 deslizable
function Is ()
{   // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);

    this.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));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    this.nav6 = (this.nav && (this.major == 5));
    this.nav6up = (this.nav && (this.major >= 5));
    this.gecko = (agt.indexOf('gecko') != -1);


    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.ie4up  = (this.ie  && (this.major >= 4));
    this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5_5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
    this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);
    this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6    = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
    this.ie6up  = (this.ie  && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);
    this.mac    = (agt.indexOf("mac")!=-1);
}

var is;
var isIE3Mac = false;
// this section is designed specifically for IE3 for the Mac

if ((navigator.appVersion.indexOf("Mac")!=-1) && (navigator.userAgent.indexOf("MSIE")!=-1) && 
(parseInt(navigator.appVersion)==3))
       isIE3Mac = true;
else   is = new Is(); 

function GetObjectStyle(objectId) {
    // cross-browser function to get an object's style object given its id
    if (document.layers && document.layers[objectId]) {
        // NN 4 DOM.. note: this won't find nested layers
        return document.layers[objectId];
    }else  if(document.getElementById && document.getElementById(objectId)) {
        // W3C DOM
        return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
        // MSIE 4 DOM
        return document.all(objectId).style;
    } else {
        return false;
    }
} // GetObjectStyle

//Opciones de cerrar, maximizar, minimizar publicidad en Netscape
function cerrarPubNetscape(){
	document.Flotante.visibility="hidden";
}

function miniPubNetscape(){
	document.Flotante.resizeTo(240,11);	
}

function maxiPubNetscape(){
	document.Flotante.resizeTo(240,515);	
}

//Opciones de cerrar, maximizar, minimizar publicidad en Explorer

function cerrarPubExplorer(capa){
	if (document.all)
	{
		document.all(capa).style.visibility="hidden";
		document.all("anunciante").style.visibility="hidden";
	}
	else
	{
		 document.getElementById(capa).style.visibility="hidden";
		 document.getElementById("anunciante").style.visibility="hidden";
	}
}

function miniPubExplorer(capa){
	if (document.all)
	{
		document.all(capa).style.clip = 'rect('+0+' '+240+' '+11+' '+0+')';
	}
	else
	{
		//document.getElementById(capa).style.clip = 
		document.getElementById("anunciante").style.visibility="hidden";
	}
}

function maxiPubExplorer(capa){
	if (document.all)
	{
		document.all(capa).style.clip = 'rect('+0+' '+240+' '+515+' '+0+')';
	}
	else
	{
		document.getElementById("anunciante").style.visibility="visible";
	}
}

function wRefresh() {
	wMark.top = posY + (navDOM?pageYOffset:document.body.scrollTop);
}


//////////////////////////////////////////////////////////////////////////

function setVals() {

//barW = 0; // scrollbar compensation for PC Nav
//barH = 0;
	if (navDOM)
	{
		//if (document.height > innerHeight) barW = 20;
		//	if (document.width > innerWidth) barH = 20;
	}
	else 
	{
		innerWidth = document.body.clientWidth;
		innerHeight = document.body.clientHeight;
	}
	
	posX = 250;
	if (primeravez)
	{
		posY = altura - 2;
	}
	else
	{
		posY = 2;
	}
	primeravez = false;
	wRefresh();
}

function pinta()
{
	
	if  ( posY >= 29 )
	{
		posY-=20;
		setTimeout('pinta()',30);
	}
	else
	{
		posY = 2;	
	}
	if ((is.nav4 || is.nav4up) && posY<30)
	{
		markid = setInterval("wRefresh()",markRefresh);
	}
	wRefresh();
}

function markMe() {
	if (is.nav4)
	{
		document.layers["Flotante"].visibility = "show";
	}
	else
	{
		var ObjectStyleBarra = GetObjectStyle("Flotante");
		var ObjectStyleCreatividad = GetObjectStyle("anunciante");
    		if (ObjectStyleBarra) {  ObjectStyleBarra.visibility = "visible";  }
		if (ObjectStyleCreatividad) {  ObjectStyleCreatividad.visibility = "visible";  }
	}
	if ( (is.ie5up ||  is.nav4up)  && !(is.mac) )
	{
		setVals();
		window.onresize=setVals;
		window.onscroll=setVals;
		pinta();
	}
} 
