


//MODIFICABLES/////////////////////////////////////////////////
///////////////////////////////////////////////////////////////


//SETEA EL TITULO
function titleInit(title,obj){

	if(typeof obj.tit_img!="undefined") title.innerHTML+="<div style='background:#FFFFFF;height:70px;padding-left:25px;padding-top:15px;'><img style='cursor:pointer' src='"+ruta+idioma+"/imgs/"+obj.tit_img+".png' /></div>";
	
}

function footInit(foot){

	foot.innerHTML+="<div style='height:"+(popUP.fh-5)+"px;text-align:right;padding-top:0.5em;'><a href='javascript:popUP.closePop();' title='"+txt_close+"'><img id='img_close' class='png' src='"+ruta+"content/css/skin/classic/icons/close.png' /></a></div>";
	
}

//SETEA EL CONTENEDOR
function contentInit(content,obj){
}

//SETEA EL IFRAME
function iframeInit(iframe,obj){
	iframe.style.backgroundColor="#FFFFFF"
}


//FIN_MODIFICABLES/////////////////////////////////////////////
///////////////////////////////////////////////////////////////


//DETECCIÓN DE IE6
nav_detection=navigator.userAgent.search(/MSIE 6/)
if(nav_detection>0)var IE6=true
else var IE6=false

nav_detection=navigator.userAgent.search(/MSIE 7/)
if(nav_detection>0)var IE7=true
else var IE7=false


//CÓDIGO FIJO/////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////



var INIT=false
var popUP = new Object()
popUP.destoyObject=null
if(IE7==true)popUP.tps=100;//tiempo en que tarda en aparecer la capa de sombra
else popUP.tps=500;
popUP.w=null
popUP.h=null
popUP.content=null
popUP.cw=null//content width
popUP.ch=null//content height
popUP.th=20//title height
popUP.fh=45//footer height
popUP.opacity=97 //transparencia de la sombra
popUP.overlayColor="#333333"//Color de la sombra
popUP.mode=""







//HABRE UN IFRAME
popUP.mensaje=function(txt,width,height,object){
	this.mode="mensaje"
	if(typeof object=="undefined")object=""
	this.w=document.documentElement.clientWidth;
	this.h=document.documentElement.clientHeight;
	
	this.cw=width
	this.ch=height

	popUP.init(object)
	setTimeout("popUP.openMensaje('"+txt+"','"+this.cw+"','"+this.ch+"')",this.tps);
	

	
}

popUP.openMensaje=function(txt){



	popUP.content.innerHTML+=txt
	
	setTimeout("popUP.openContent("+(this.tps/5)+")",0);
	
}

//HABRE UN IFRAME
popUP.flash=function(url,width,height,object){
	this.mode="flash"
	if(typeof object=="undefined")object=""
	this.w=document.documentElement.clientWidth;
	this.h=document.documentElement.clientHeight;
	
	this.cw=width
	this.ch=height

	popUP.init(object)
	setTimeout("popUP.openFlash('"+url+"','"+this.cw+"','"+this.ch+"')",this.tps);
	

	
}

popUP.openFlash=function(url){



	popUP.content.innerHTML+='<div id="galeria_flash_max" style="background:#3D3D3D;" >&nbsp;</div>'
	var iflash=document.getElementById("galeria_flash_max")

	iflash.style.width=this.cw+"px"
	iflash.style.height=(this.ch-this.th-this.fh)+"px"
	
	setTimeout("popUP.openContent("+(this.tps/5)+")",0);
	

	
	
	setTimeout("mymovie_max.write('galeria_flash_max')",(this.tps));
	
}
//HABRE UN IFRAME
popUP.iframe=function(url,width,height,object){
	
	if(typeof object=="undefined")object=""
	else this.th=80
	this.w=document.documentElement.clientWidth;
	this.h=document.documentElement.clientHeight;

	if(typeof width=="undefined") this.cw=Math.round(this.w*0.8)
	else this.cw=width
	if(typeof height=="undefined") this.ch=Math.round(this.h*0.8)
	else this.ch=height
	if(this.cw>Math.round(this.w*0.8)) this.cw=Math.round(this.w*0.8)
	if(this.ch>Math.round(this.h*0.8))this.ch=Math.round(this.h*0.8)
	popUP.init(object)
	setTimeout("popUP.openFrame('"+url+"','"+this.cw+"','"+this.ch+"')",popUP.tps);


	
}

popUP.openFrame=function(url){


	//CREA EL IFRAME
	var iframe = document.createElement('iframe'); 
	iframe.setAttribute("src",url)
	iframe.setAttribute("id","iframe_popup")
	iframe.setAttribute("frameBorder","no")
	//PONE EL IFRAME EN LA PAGINA Y LO COLOCA
	popUP.content.appendChild(iframe)
	iframe.style.width=this.cw+"px"
	iframe.style.height=(this.ch-this.th-this.fh)+"px"
	iframeInit(iframe)
	
	if(IE6==true || IE7==true){
		setTimeout("popUP.openContent("+(this.tps/2)+")",(this.tps*2));
	}else {
		iframe.onload=function(){
		popUP.openContent(300)}
	}
	

	
	
}

popUP.openContent=function(tps){
	changeStyle("width",this.cw,"content_popup")
	//changeStyle("height",Math.round(height-200),"content_popup")
	//sizeTo("width","content_popup", width, width, 0)
	sizeTo("height","content_popup", 100, this.ch,tps/2)
	opacity("content_popup",0,100, tps)
	if(this.fh>0){popUP.openFoot(tps)}
}
//CREA LA CAPA DE SOMBRA SI NO EXITE, Y la pone en su sitio.

popUP.openFoot=function(tps){
	this.foot = document.createElement('div'); 
	this.foot.style.height=this.fh+"px"
	this.content.appendChild(this.foot)
	footInit(this.foot)
	setTimeout("pngFIX()",10)
	
}
popUP.closePop=function(){
	if(this.mode=="flash")this.content.innerHTML=""
	opacity("sombra_popup",popUP.opacity,0, popUP.tps)
	opacity(this.destroyObject.id,100,0, popUP.tps)
	if(IE6===true)	post_ie6()
	setTimeout("document.body.removeChild(popUP.destroyObject)",popUP.tps)
}

popUP.init=function(object){
	if(IE6===true)	pre_ie6()
	if(INIT==false){
		var sombra = document.createElement('div'); 
		sombra.appendChild(document.createTextNode(' ')); 
		sombra.setAttribute("id","sombra_popup")
		sombra.onclick=function(){popUP.closePop()}
		document.body.appendChild(sombra)
		INIT=true
	}
	
	this.init_html_element("sombra_popup",998)
	changeOpac(0, "sombra_popup")
	//PONER EL ESTILO DE SOMBRA CORRECTO
	sombra=document.getElementById("sombra_popup");
	if(IE6==true){
		sombra.style.width=document.body.clientWidth+"px"
		sombra.style.height=document.body.clientHeight+"px"
	}else {
		sombra.style.width=screen.availWidth+"px"
		sombra.style.height=screen.availHeight+"px"
	}
	
	sombra.style.backgroundColor=this.overlayColor;
	opacity("sombra_popup",0,popUP.opacity, popUP.tps)
	this.content = document.createElement('div'); 
	this.content.setAttribute("id","content_popup")
	this.content.className="clearfix";
	contentInit(this.content,object)
	document.body.appendChild(this.content)
	popUP.init_html_element("content_popup",999)
	
	this.content.style.width=this.cw+"px"
	this.content.style.height="100px"
	this.content.style.backgroundColor=this.OverlayColor
	//CENTRA EL IFRAME

	this.content.style.overflow="hidden"
	centrar(this.content,this.cw,this.ch)
	
	//BARRA DE TITULO
	this.title = document.createElement('div'); 
	this.title.style.height=this.th+"px"
	this.content.appendChild(this.title)
	titleInit(this.title,object)
	
	this.destroyObject=popUP.content
	
}



function centrar(object,width,height){
	centrado_horizontal(object,width)
	centrado_vertical(object,height)
}

function centrado_horizontal(object,width){
	object.style.marginLeft=((popUP.w-width)/2)+"px"
}

function centrado_vertical(object,height){
	if(IE6===true)object.style.marginTop=(((popUP.h-height)/2)+document.documentElement.scrollTop)+"px"
	else object.style.marginTop=((popUP.h-height)/2)+"px"
}
//COLOCA UN ELEMENTO POR ENCIMA DE TODO, en el punto 0,0
popUP.init_html_element=function(id,zindex){
	var elem=document.getElementById(id);
	
	if(IE6==true){
		elem.style.position="absolute"
	}else {
		elem.style.position="fixed"
	}
	elem.style.zIndex=zindex
	elem.style.left="0px"
	elem.style.top="0px"
	changeOpac(0, id)
	
}

//PARA QUE SE VEA BIEN EN IE6////////////////////////
function pre_ie6(){
	for(j=0;j<document.forms.length;j++){
		form=document.forms[j]
		for(i=0;i<form.length;i++){
			
			var c = form[i]
			if(c.type=="select-one" ){
				c.style.visibility="hidden"
			}
		
		}
	}

}

function post_ie6(){
	for(j=0;j<document.forms.length;j++){
		form=document.forms[j]
		for(i=0;i<form.length;i++){
			
			var c = form[i]
			if(c.type=="select-one" ){
				c.style.visibility=""
			}
		
		}

	}
	
}
///////////////////////////////////////////////////



///FUNCIONES DE RESIZE/////////////////////////////

function sizeTo(variable,id, Start, End, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(Start > End) {
		for(i = Start; i >= End; i--) {
			setTimeout("changeStyle('"+variable+"'," + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		
	} else if(Start < End) {
		for(i = Start; i <= End; i++)
			{
			setTimeout("changeStyle('"+variable+"'," + i + ",'" + id + "')",(timer * speed));
			timer++;
			}
			
	}
}

   /**
    * Begins quickly and decelerates towards end.  (quadratic)
    * @param {Number} t Time value used to compute current value.
    * @param {Number} b Starting value.
    * @param {Number} c Delta between start and end values.
    * @param {Number} d Total length of animation.
    * @return {Number} The computed value for the current animation frame.
    */
function easeOut(t, b, c, d) {
   	return -c *(t/=d)*(t-2) + b;
}

function changeStyle(variable,valor,id){
	var object = document.getElementById(id); 
	
	object.style[variable]=valor+"px";
	
	if(variable=="width")centrado_horizontal(object,valor)
	if(variable=="height")centrado_vertical(object,valor)
}


//FUNCIONES DE TRANSPARENCIA ///////////////////////////////////////////////////////////////////////
function shiftOpacity(id, millisec,opa) {
      //SI El elemento es visible lo muestra, sino lo oculta
      if(document.getElementById(id).style.opacity == 0) {
            
			opacity(id, 0, opa, millisec);
      } else {
		  	
            opacity(id, opa, 0, millisec);
      }
}

function opacity(id, opacStart, opacEnd, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;

	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
		
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
			}
			
	}
}






//Aplica transparencia compatible con la mayoría de navegadores
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
	
	if(opacity<1) document.getElementById(id).style.display="none";
	if(opacity>1 && document.getElementById(id).style.display=="none") {
		document.getElementById(id).style.display="block";
	}
}



function pngFIX(){
	
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters)) 
{
   for(var i=0; i<document.images.length; i++)
   {
      var img = document.images[i]
      var imgName = img.src.toUpperCase()
      if (img.className=="png" )
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText 
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
         img.outerHTML = strNewHTML
		 i = i-1
      }
   }
}
}
