var alto_final_menu;
var menuActivo = "";
var menuActivoAncho;
var menuActivoAlto;
var menuActivoId;

function CambiaClase(id, nuevaClase) {
		objeto = document.getElementById(id);
		
		if (objeto.className == 'oculto'){
			document.getElementById(id).className = nuevaClase;
		}
		else {
			document.getElementById(id).className = 'oculto';
		}
	}

function cambiaImagen (id, estado) {
	
	imagenMenu = document.getElementById("img_" + id);
	//alert ("img_" + id)
	if (estado == 1) {
		imagenMenu.src = "/img/img_" + id + "_on.gif";
		}
	if (estado != 1 && menuActivo != document.getElementById(id)) {
		imagenMenu.src = "/img/img_" + id + ".gif";
		}
	}

function abrirListado(id, ancho, alto, num_filas) {
	// cierra todas la que está abierta 
	if (menuActivo != ""){
	menuActivo.style.backgroundColor = "";
	menuActivo.style.width = menuActivoAncho + 'px';
	menuActivo.style.height = menuActivoAlto + 'px';	
	
	imgCerrar = "cerrar_" + menuActivoId;
	document.getElementById(imgCerrar).style.display = "none";
	}
	
	// empieza a abrir
	alto_final_menu = num_filas*19+ alto;
	objeto = document.getElementById(id);
		menuActivoAlto = alto;
		menuActivoAncho = ancho;
		menuActivo = objeto;
		menuActivoId = id;
		
	imgCerrar = "cerrar_" + id;
	tabla = "tabla_" + id;
	objeto.style.backgroundColor = "#ff0000";
	changeOpac (0, tabla);	


	objeto.style.width = ancho + 'px';
	objeto.style.height = alto + 'px';	
	amplia_ancho();
}

function amplia_ancho(){
	if (parseInt(objeto.style.width) < 550) 
		{
			objeto.style.width = parseInt(objeto.style.width) + 40 + 'px';
			setAncho = setTimeout(amplia_ancho,10);
		}
	else
		{
			document.getElementById(imgCerrar).style.display = "block";
			amplia_alto(); 
		}
		
}

function amplia_alto(){
		clearTimeout (setAncho);
		if (parseInt(objeto.style.height) < alto_final_menu) 
			{
				objeto.style.height = parseInt(objeto.style.height) + 19 + 'px';
				setAlto = setTimeout(amplia_alto,10);
			}
		else {
			clearTimeout (setAlto);
			opacity(tabla, 0, 100, 10);
			}
	}
function cerrarListado(id, ancho, alto){
	
	//imagenMenu = document.getElementById("img_" + id);
	document.getElementById("img_series").src = "/img/img_series.gif";
	document.getElementById("img_peliculas").src = "/img/img_peliculas.gif";
	document.getElementById("img_otros").src = "/img/img_otros.gif";
	
	
	menuActivo = "";

	objeto = document.getElementById(id);
	objeto.style.backgroundColor = "";
	objeto.style.width = ancho + 'px';
	objeto.style.height = alto + 'px';	
	
	imgCerrar = "cerrar_" + id;
	document.getElementById(imgCerrar).style.display = "none";
	
	}
// --------------------------------------------- scroll -----------------------------------
var top_actual_contenedor_galeria = 0;
var top_actual_contenedor_cast = 0;

var nombre_top_actual;

function scroll_vertical(id, variacion, filas) {
	
	maximo = -((filas - 1 ) * variacion) ;

	nombre_top_actual = "top_actual_" + id;

	if ((variacion > 0 && eval(nombre_top_actual) < 0 ) || (variacion < 0  && eval(nombre_top_actual) > -maximo ))
		{
		eval (nombre_top_actual + " = " + nombre_top_actual + " + " + variacion + ";");
		document.getElementById(id).style.top = eval(nombre_top_actual) + "px";
		}
}
// ----------------------------------------------------------------------------------------
	
// cambio de opacidad 
function opacity(id, opaIni, opaFin, millisec) {
		if(typeof(i_opa)!="undefined"){clearInterval(i_opa)}
		//i =0;
		i = opaIni;
		i_opa=setInterval(function(){
								   changeOpac(i,id)
								   if(i==opaFin){clearInterval(i_opa)}
								   i+=10
								   },millisec)
}



//change the opacity for different browsers
function changeOpac(opa, id) {
	
	//alert ("Cambio: " + id + "    a: " +opa)
	
	var object = document.getElementById(id).style; 
	object.opacity = (opa / 100);					// cambia opacidad en Mozila nuevo
	object.MozOpacity = (opa / 100);				// cambia opacidad en Mozila viejo
	object.KhtmlOpacity = (opa / 100);				// cambia opacidad en konkeror
	object.filter = "alpha(opacity=" + opa + ")";	// cambia opacidad en IE
}



// ---------------------------  abrir ampliacion de imagenes --------------------

function ampliarImagen(serie, nombre, texto) {
	
	//var imagen = getImage(document.getElementById("fotoAmpliada"));
	
	document.getElementById("fotoAmpliada").src= "media/" + serie + "/img/" + nombre;

	var newImg =  new Image();
	newImg.src = document.getElementById("fotoAmpliada").src;
	
	if(texto != "")
	{
		i_comp = setInterval("chequeoCarga('"+serie+"','"+nombre+"','"+texto+"')",20);
	}
	else
	{

		i_comp = setInterval("chequeoCarga('"+serie+"','"+nombre+"','')",20);
	}
}

function chequeoCarga( serie, nombre, texto)
{
	var newImg =  new Image();
	newImg.src = document.getElementById("fotoAmpliada").src;
	if(newImg.width != 0)
	{
		clearInterval(i_comp);
		continuaAmpliarImagen(serie, nombre, texto);
	}
}
			
function continuaAmpliarImagen(serie, nombre, texto) {
	var newImg =  new Image();
	newImg.src = document.getElementById("fotoAmpliada").src;
	var ancho = newImg.width;
	ancho = ancho ;
	document.getElementById("ampliacion").style.width= ancho+"px";	
	document.getElementById("encabezado").style.width= (ancho-4) + "px";
	document.getElementById("textoFoto").style.width= (ancho-8) + "px";
	
	document.getElementById("velo").style.display = "block";

	divFoto = document.getElementById("ampliacion");
	


	divFoto.style.display = "block";
	//divFoto.style.left = "-800px";

			i = 0;
			i_opa = setInterval(function(){
									changeOpac(i,"velo")
										if(i==60){
													clearInterval(i_opa);	
													//divFoto.style.left = "0px";
													//divFoto.style.top = "60px";
													document.getElementById("velo").style.height = "0";
													document.getElementById("velo").style.height = "100%";
												}
												i+=10
											},20)
			document.getElementById("textoFoto").innerHTML = texto;
			if (texto =="") {
					document.getElementById("textoFoto").style.display = "none";
			}
			else
			{
					document.getElementById("textoFoto").style.display = "block";
			}	
	}
function ampliarTexto(origenTexto, tituloSerie, texto) {
	
	document.getElementById("velo").style.display = "block";

	divTexto = document.getElementById("ampliacion_texto");
	
	divTexto.style.display = "block";

			i = 0;
			i_opa = setInterval(function(){
										changeOpac(i,"velo")
										if(i==60){
													clearInterval(i_opa);	
													//divFoto.style.left = "0px";
													//divFoto.style.top = "60px";
													document.getElementById("velo").style.height = "0";
													document.getElementById("velo").style.height = "100%";
												}
												i+=10
											},20)
			document.getElementById("textoAmpliado").innerHTML = texto;
			document.getElementById("origenTexto").innerHTML = origenTexto;
			document.getElementById("tituloSerie").innerHTML = tituloSerie;

	}
function cerrarAmpliacion() {
		changeOpac(0,"velo");
		document.getElementById("velo").style.display = "none";
		document.getElementById("ampliacion_texto").style.display = "none";
		document.getElementById("ampliacion").style.display = "none";
		document.getElementById("fotoAmpliada").src= "";
		//document.getElementById("ampliacion").style.left = "-800px";
		}
// ---------------------------  abrir texto ampliado --------------------
function ampliaTexto() {

	document.getElementById("velo").style.display = "block";
	
}

// Control Clase de ejecución de archivos ShockWave Flash
// (c)2006 The Mad Pixel Factory --- http://www.madpixel.es


obj_swf=function(){
        this.salida_div=false
        this.trace=false
        this.codificarFlashVars=false
        this.a_FlashVars=new Array()
}
obj_swf.prototype.FNtrace=function(){
        this.trace=true
        return true
}
obj_swf.prototype.FNcodificarFlashVars=function(){
        this.codificarFlashVars=true
        return true
}
obj_swf.prototype.FNid_salida=function(p_id_salida){
        if(typeof(p_id_salida)!="undefined"){
                if(document.getElementById(p_id_salida)){
                        this.salida_div=true
                        this.obj_div=document.getElementById(p_id_salida)
                }
        }
}
obj_swf.prototype.FNborrar=function(){
        delete this
}
obj_swf.prototype.FNflashvars=function(p_cad){
        this.a_FlashVars.push(p_cad);
        return true
}
obj_swf.prototype.FNgfx_swf=function(){
        //Comprueba parametros básicos
        if(typeof(this.classid)=='undefined'){this.classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'}
        if(typeof(this.codebase)=='undefined'){this.codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'}
        if(typeof(this.quality)=='undefined'){this.quality='high'}
        if(typeof(this.type)=='undefined'){this.type='application/x-shockwave-flash'}
        if(typeof(this.pluginspage)=='undefined'){this.pluginspage='http://www.macromedia.com/go/getflashplayer'}
        if(typeof(this.swliveconnect)=='undefined'){this.swliveconnect="true"}
        if(typeof(this.allowscriptaccess)=='undefined'){this.allowscriptaccess="true"}
        if(typeof(this.id)=='undefined'){var nId=Math.round(Math.random()*100);this.id='swf'+nId}
        //--
        //Crea arrays de contenido
        this.a_object_propios=new Array()
        this.a_comunes=new Array()
        this.a_object_variables=new Array()
        this.a_embed_propios=new Array()
        this.a_embed_variables=new Array()
        //--
        //Comprueba que no hay array de FlashVars - de lo contrario sobreescribe la variable flashvars
                if(this.a_FlashVars.length>0){
                        if(this.codificarFlashVars){
                                r=0;while(this.a_FlashVars[r]){
                                        var v_variable=this.a_FlashVars[r].split("=")[0]
                                        var v_valor=this.a_FlashVars[r].split("=")[1]
//                                        this.a_FlashVars[r]=v_variable+"="+escape(v_valor)
                                        this.a_FlashVars[r]=v_variable+"="+v_valor
                                        r++
                                }
                        }
                        this.flashvars=this.a_FlashVars.join("&")
                        
                }
        //--
        //Revisa contenido adquirido
        for(parametros in this){
                var cNomParametro=parametros.toLowerCase()
                var cValorParametro=eval("this."+parametros)
                if(typeof(cValorParametro)=="string"){
                        switch (cNomParametro){
                                case "classid":
                                case "codebase":
                                case "onafterupdate":
                                case "onbeforeupdate":
                                case "onblur":
                                case "oncellchange":
                                case "onclick":
                                case "ondblClick":
                                case "ondrag":
                                case "ondragend":
                                case "ondragenter":
                                case "ondragleave":
                                case "ondragover":
                                case "ondrop":
                                case "onfinish":
                                case "onfocus":



                                case "onhelp":
                                case "onmousedown":
                                case "onmouseup":
                                case "onmouseover":
                                case "onmousemove":
                                case "onmouseout":
                                case "onkeypress":
                                case "onkeydown":
                                case "onkeyup":
                                case "onload":
                                case "onlosecapture":
                                case "onpropertychange":
                                case "onreadystatechange":
                                case "onrowsdelete":
                                case "onrowenter":
                                case "onrowexit":
                                case "onrowsinserted":
                                case "onstart":
                                case "onscroll":
                                case "onbeforeeditfocus":
                                case "onactivate":
                                case "onbeforedeactivate":
                                case "ondeactivate":
                                case "type":
                                        this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
                                        break;
                                case "width":
                                case "height":
                                case "align":
                                        this.a_comunes.push( cNomParametro+'="'+cValorParametro+'"' )
                                        break;
                                case "type":
                                case "pluginspage":
                                case "allowscriptaccess":
                                case "width":
                                case "height":
                                case "align":
                                case "vspace":
                                case "hspace":
                                case "class":
                                case "title":
                                case "accesskey":
                                case "swliveconnect":
                                case "tabindex":
                                        this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
                                        break;
                                case "id":
//                                      this.a_object_propios.push( cNomParametro+'="'+cValorParametro+'"' )
                                        this.a_object_propios.push( 'name'+'="'+cValorParametro+'"'  )
                                        this.a_embed_propios.push( cNomParametro+'="'+cValorParametro+'"' )
                                        this.a_embed_propios.push('name'+'="'+cValorParametro+'"' )
                                        break;
                                case "movie":
                                        this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
                                        this.a_embed_propios.push('src'+'="'+cValorParametro+'"' )
                                        break;
                                case "flashvars":
                                        //Revision el contenido de FlashVars para evitar problemas de comillas y caracteres especiales
//                                      if(cValorParametro.indexOf('"')!=-1 || cValorParametro.indexOf("'")!=-1){
                                        if(cValorParametro.indexOf('"')!=-1){
                                                a_cValorParametro=cValorParametro.split('"').join('\'')
                                                cValorParametro=a_cValorParametro
                                                //cValorParametro=escape(cValorParametro)
                                        }
                                        this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
                                        this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
                                        //--
                                        break;
                                default :
                                        this.a_object_variables.push( '<param name="'+cNomParametro+'" value="'+cValorParametro+'" />' )
                                        this.a_embed_variables.push( cNomParametro+'="'+cValorParametro+'"' )
                                        break;
        
                        }
                }
        }
        //--
        
        this.a_object_propios=this.a_object_propios.join(" ")
        this.a_comunes=this.a_comunes.join(" ")
        this.a_embed_propios=this.a_embed_propios.join(" ")
        this.a_object_variables=this.a_object_variables.join("\n")
        this.a_embed_variables=this.a_embed_variables.join(" ")
        
        
        //Genera salida
        cad=''
        cad+=('<object '+this.a_object_propios+' '+this.a_comunes+' >'+'\n')
        cad+=(''+this.a_object_variables +'\n')
        cad+=('<embed '+this.a_embed_propios+' '+this.a_comunes+' '+this.a_embed_variables+'></embed>'+'\n')
        cad+=('</object>'+'\n')
        
        if(this.salida_div){
                this.obj_div.innerHTML=cad //Salida a etiqueta ID
        }else{
                document.write(cad) //Escritura directa sobre HTML
        }
        //--
        
        if(this.trace){alert(cad)}
        
}
