var img_cargando ="<img src='/img/cargando2.gif' id='img_cargando'>";

var total_msg;
var msg;

$(document).ready(doCarrousel);

rules_rotatorHome = {
	seleccion:function(){
			var numero=parseInt($(this).text())-1;
			rules_rotatorHome.selector(numero);
			clearTimeout(rules_rotatorHome.timer);
			return false;
	},
	init : function(){
		var numero=$(".Xrotator").length;
		rules_rotatorHome.cantidad=numero;
		var i;
		for(i=1;i<=numero;i++)
		{
		var cadena="<li class=btnRotator><a href='javascript:void();' class=btnSel>" + i + "</a></li>";
		$("#rotatore").append(cadena);
		}
		$(".btnRotator").click(rules_rotatorHome.seleccion);
		$(".btnRotator").eq(0).addClass("RSelected");
		$(".Xrotator").eq(0).show();
		rules_rotatorHome.timer=setTimeout(rules_rotatorHome.rotate,5000);

	},
	rotate:function()
	{
		rules_rotatorHome.current++;
		if(!(rules_rotatorHome.current<rules_rotatorHome.cantidad))
			rules_rotatorHome.current=0;

		rules_rotatorHome.selector(rules_rotatorHome.current);
		rules_rotatorHome.timer=setTimeout(rules_rotatorHome.rotate,5000);
	},
	selector: function(num)
	{
			$(".btnRotator").removeClass("RSelected");
			$(".Xrotator").hide();
			$(".btnRotator").eq(num).addClass("RSelected");
			$(".Xrotator").eq(num).show();
	},
	current:0,
	cantidad:0
};

$(document).ready(rules_rotatorHome.init);


function aviso(texto,sel,sel2){
    var ventana = '<div class="popup3 estirar"><h2><img src="/txt/aviso.gif" alt="bases" class="titulares" /></h2><a href="#"  class="cerrar">Cerrar</a><div class="aviso"><p>'+texto+'</p></div><a href="#" id="cerrar" class="boton"><img src="/img/boton_cerrar_rojo.gif" alt="" /></a></div>';
		if(sel==undefined){
    		$("#modal").html(ventana).popUp();
		}
		else{
				if(sel2!="cerrar")
    			$().popUp2(sel,ventana,sel2);
				else
    		$("#"+sel).html(ventana).popUp(null,1);
		}
}

function galeria(texto,sel,sel2){
    var ventana = '<div class="popup3 estirar"><a href="#"  class="cerrar">Cerrar</a><div class="galeria"><p>'+texto+'</p></div><a href="#" id="cerrar" class="boton"><img src="/im/boton_cerrar_rojo.gif" alt="" /></a></div>';
		if(sel==undefined){
    		$("#modal").html(ventana).popUp();
		}
		else{
				if(sel2!="cerrar")
    			$().popUp2(sel,ventana,sel2);
				else
    		$("#"+sel).html(ventana).popUp(null,1);
		}
}







var rules_capas = {
ocultar :   function(){
               $("div.tabContenido").css('display','none');
			   $("div.tabContenidox").css('display','none');
               $("div.tSel").css('display','block');
           }
}
$(document).ready(rules_capas.ocultar);

//TABDISPLAY_BH
var rules_tab = {
    evento :   function(){
         $('a.tD').click(rules_tab.ejecutar);
         },
    ejecutar : function(){
            j = this;
           idTab = j.id.split("_")[0]+ j.id.split("_")[1];
		   $("#"+j.id.split("_")[0]+" .tabs li").attr("class","");
           //    lis   = $("#"+j.id.split("_")[0]+" .tabs li").get();
           //for (var z = 0; z<lis.length; z++)
           //    lis[z].className = "";
           //tabsH = $("#"+j.id.split("_")[0]+" .tabContenido").get();
		   $("#"+j.id.split("_")[0]+" .tabContenido").css("display","none");
		   $("#"+j.id.split("_")[0]+" .tabContenidox").css("display","none");
           //for (var i = 0; i<tabsH.length; i++){
           //    tabsH[i].style.display = "none";
           //}
           j.parentNode.className = "selected";
           $("#"+idTab).css("display","block");
           return false;
      }
}
$(document).ready(rules_tab.evento);

 //Ventana modal hecha por Javier Villarrubia (por definir la función definitiva)
/*Funcion que ubica un elemento a una determinada altura del 'screen' en posición relativa al 
 *desplazamiento del scroll-dado que utiliza 'jquery' hay que cargar previamnete la librería de 
 *'jquery'-
 *El argumento 'capa' es un string que sigue la nomenclatura de 'jquery' por ej: "#capax", ".etiquetax",
 *El segundo argumento (top) se refiere a la altura donde deseamos ubicar la capa en relacion al screen.*/
function centerScreen(capa,top) {
	var anchoDivAMostrar = $(capa).width();
 	var innerWidth = 0, innerHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
	  //Non-IE
	  innerWidth = window.innerWidth;
	  innerHeight = window.innerHeight;
	  myPageXOffset = window.pageXOffset;
	  myPageYOffset = window.pageYOffset;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	  //IE 6+ in 'standards compliant mode'
	  innerWidth = document.documentElement.clientWidth;
	  innerHeight = document.documentElement.clientHeight;
	  myPageXOffset =document.documentElement.scrollLeft;
	  myPageYOffset =document.documentElement.scrollTop;
	  
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	  //IE 4 compatible
	  innerWidth = document.body.clientWidth;
	  innerHeight = document.body.clientHeight;
	  myPageXOffset = document.body.scrollLeft;
	  myPageYOffset = document.body.scrollTop;
	}
	var x = ((innerWidth - anchoDivAMostrar) / 2) + myPageXOffset;
	var y = top + myPageYOffset;
	$(capa).css("left",x+"px");
	$(capa).css("top",y+"px");
	$(capa).show();
	return false;
}

$(document).ready(function(){
    $("body").append("<div id=\"overlayer\" style=\"position:absolute;top:0px;left:0px;z-index:9900;display:block;margin:0px;padding:0px;float:none;clear:none;background-color:#000000;\"></div>");
    //$("body").append("<div id=\"modal\" style=\"display:block;position:absolute;z-index:10000;width:auto;min-height:600px;height:auto !important;height:600px;\"></div>");
    $("body").append("<div id=\"modal\" style=\"display:block;position:absolute;z-index:10000;width:auto;height:auto;\"></div>");
});
jQuery.altura=function(){
    return self.innerHeight||jQuery.boxModel&&document.documentElement.clientHeight||document.body.clientHeight;
};
jQuery.anchura=function(){
    return self.innerWidth||jQuery.boxModel&&document.documentElement.clientWidth||document.body.clientWidth;
};
jQuery.scrollTop=function(){
    return self.pageYOffset||jQuery.boxModel&&document.documentElement.scrollTop||document.body.scrollTop;
};
jQuery.scrollLeft=function(){
    return self.pageXOffset||jQuery.boxModel&&document.documentElement.scrollLeft||document.body.scrollLeft;
};
jQuery.fn.centroLeft=function(){
    var w1=Math.round(jQuery.anchura()/2),w2=Math.round(this.width()/2),left=w1-w2+jQuery.scrollLeft();
    return left;
};
jQuery.fn.centroTop=function(){
    var h1=Math.round(jQuery.altura()/2),h2=Math.round(this.height()/2),top=h1-h2+jQuery.scrollTop();
    return top; 
};
jQuery.fn.popUp2=function(sel,html,sel2){
		if(sel2!=undefined)
			$("div#"+sel2).fadeOut();
    $("body").append("<div id=\""+sel+"\" style=\"display:block;position:absolute;z-index:10100;width:auto;height:auto;\"></div>");
		var pop=$("div#"+sel);
		pop.html(html);
    var top=pop.centroTop(),left=pop.centroLeft();
    pop.css("top",top).css("left",left);
    pop.find("#cerrar,.cerrar,a.cancelar").bind("click",function(){pop.popDown2(sel2);return false;});
    pop.fadeIn().show().siblings().find("object,embed,select,iframe").css("visibility","hidden");
    $("div#overlayer").css({"opacity":0.9,"width":jQuery.anchura(),"height":$(document).height()}).fadeIn(function(){$("div#overlayer").show();});
};
jQuery.fn.popDown2=function(sel2){
    this.fadeOut().hide().empty().remove();
		if(sel2!=undefined)
			$("div#"+sel2).fadeIn();
};
jQuery.fn.popUp=function(distancia,nullbind){
    var div=this,id=this.attr("id");
    var top=distancia==undefined||isNaN(distancia)?this.centroTop():jQuery.scrollTop()+distancia,left=this.centroLeft();
    this.css("top",top).css("left",left);
    if(!nullbind) this.find("#cerrar,.cerrar,a.cancelar").bind("click",function(){div.popDown();return false;});
    this.fadeIn().show().siblings().find("object,embed,select,iframe").css("visibility","hidden");
    $("div#overlayer").css({"opacity":0.9,"width":jQuery.anchura(),"height":$(document).height()}).fadeIn(function(){$("div#overlayer").show();});
};
jQuery.fn.popDown=function(){
    $("div#overlayer").fadeOut(function(){$("div#overlayer").hide();});
    this.fadeOut().hide().empty();
    this.siblings().find("object,embed,select,iframe").css({"visibility":"visible"});
};
jQuery.fn.pre_loading=function(sel,html,opacity,modal){
    $("body").append("<div id=\"pre_loading_over\" style=\"position:absolute;top:0px;left:0px;z-index:10100;display:block;margin:0px;padding:0px;float:none;clear:none;\"></div>");
    $("body").append("<div id=\"pre_loading\" style=\"position:absolute;z-index:10200;width:auto;height:auto;\"></div>");
		var pop=$("div#pre_loading");
		var over=$("div#pre_loading_over");
		var elem=$(sel);
		pop.html(html);
		over.css({"width":elem.width(),"height":elem.height(),"opacity":0});
		if(modal==undefined){
			var elemTop=elem.eTop();
			var elemLeft=elem.eLeft();
    	var dimT=Math.round((elem.height()/2)+elem.eTop());
    	var dimL=Math.round((elem.width()/2)+elem.eLeft());
			var top=dimT-pop.height()/2;
			var left=dimL-pop.width()/2;
		}
		else{
			var elemTop=over.centroTop();
			var elemLeft=over.centroLeft();
			var top=pop.centroTop();
			var left=pop.centroLeft();
		}
    pop.css("top",top);
		pop.css("left",left);
		over.css("top",elemTop);
		over.css("left",elemLeft);
		if(opacity!=undefined){
			elem.fadeTo("fast",opacity);
		}
};
jQuery.fn.post_loading=function(sel,opacity){
		var pop=$("div#pre_loading");
		var over=$("div#pre_loading_over");
		over.remove();
		pop.remove();
		if(opacity!=undefined){
			var elem=$(sel);
			elem.fadeTo("slow",opacity);
		}
};
jQuery.fn.eTop=function(){
	var nodo=this[0];
	var etop=0;		
	while(nodo.tagName!="BODY"){
		etop+=nodo.offsetTop;
		nodo=nodo.offsetParent;
	}
	return etop;
};
jQuery.fn.eLeft=function(opts){
	var nodo=this[0];
	var eleft=0;
	while(nodo.tagName!="BODY"){
		eleft+=nodo.offsetLeft;
		nodo=nodo.offsetParent;
	}
	return eleft;
};




		
function doCarrousel() {

    $(".carrouselHome").jCarouselLite({
        btnNext: ".carButtonAz.next",
        btnPrev: ".carButtonAz.prev",
		visible: 6,
		circular: false
    });
  
}


rules_galerias = {
		abrirGaleria : function() {
			var galeriac=$(this).attr("href");
			var codigo="<IFRAME SRC=\"" +galeriac+ "\" width=540 height=600></IFRAME>";
			galeria(codigo);
			return false;
		   },
		abrirGaleriaPropiaPagina : function() {
			var galeriac=$(this).attr("href");
			$("img.imgFotoGal").attr("src",galeriac);	
			return false;
		   },
		abrirPodcast : function() {
			var galeriac="/rss_add.aspx";
			var codigo="<IFRAME SRC=\"" +galeriac+ "\" width=480 height=280></IFRAME>";
			galeria(codigo);
			return false;
		   },
		evento : function() {
			    $("a.openGaleria").click(rules_galerias.abrirGaleria);
				$("a.enlPodcast").click(rules_galerias.abrirPodcast);
				$("a.openGaleriaPG").click(rules_galerias.abrirGaleriaPropiaPagina);
		   }
};
rules_players = {
	openPlayerPop: function ()
	{
	window.open($(this).attr("href"),'_popPlayer','width=796,height=560');
	return false; 
	},
	evento : function()
	{
		$("a.openPlayerPop").click(rules_players.openPlayerPop);
	}

}
$(document).ready(rules_galerias.evento);
$(document).ready(rules_players.evento);

$(document).ready(doGale);
function doGale()
{
$(".imgGale1").each(function(){
				var h=$(this).height();
				var w=$(this).width();
				var r=h/w;
				if(h>=w)
				{
					var h2=80;
					var w2=(80*w)/h;
					$(this).height(h2).width(w2);
				}
				if(w>=h)
				{
					var w2=80;
					var h2=(80*h)/w;
					$(this).height(h2).width(w2);
				}
			})

}


$(document).ready(function(){$(".Nborder").corner();});
$(document).ready(function() {
				var xmItem;
				xMenuItem=0;
				if(xMenuItem)
				{
					xmItem=parseInt(xMenuItem);
					$("#xmenu1 li").eq(xmItem).addClass("current");
				}
				});
$(document).ready(function() {

            $("#xmenu1").lavaLamp({
                fx: "backout",
                speed: 700,
                click: function(event, menuItem) {
                    return true;
                }
            });
        });
$(document).ready(function(){$("#xmenu1 .back").corner("5px");});

function log(prm) {
	if (prm != '')
		document.write("<img width='1' height='1' border='0' src='/st.aspx?p=" + prm + "&rnd=" + Math.random() + "'/>");
}




/*Cambio entre ingles y Espanol en las paginas que lo tengan*/

function swDesaEng()
{
	$("div#DesaSpa").fadeOut().hide();
	$("div#DesaEng").fadeIn().show();
}

function swDesaSpa()
{
	$("div#DesaEng").fadeOut().hide();
	$("div#DesaSpa").fadeIn().show();
}

function _poPrintEng()
{
	$("div#DesaSpa").hide();
	$("div#DesaEng").show();
	window.print();

}

function _poPrintEsp()
{
	$("div#DesaEng").hide();
	$("div#DesaSpa").show();
	window.print();

}



$(document).ready(function() {
			$("a#swDesaSpa").click(swDesaSpa);
			$("a#swDesaEng").click(swDesaEng);
			$("a#_poPrintEng").click(_poPrintEng);
			$("a#_poPrintEsp").click(_poPrintEsp);
			if($("div#DesaEng").text()=="")
				{
					$("a#swDesaEng").hide();
					$("a#_poPrintEng").hide();
				}
			
			});

/*Videos WMA*/

$(document).ready(function() {
		$("img.itmVidWMA").click(itmVidWMA);
});

function itmVidWMA()
{
	var pplayer=$(this).siblings("#VIDEOWMV")[0];
	$(this).hide();
	if(!pplayer.controls)
	{
		var bck=$(this).siblings("#VIDEOWMVBCK");
		var source=bck.attr("source");
		var temp='<EMBED type="application/x-mplayer2" width="100%" height="100%" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="' + source + '" " autostart="1" showstatusbar="0" showcontrols="1"></EMBED>'
		bck.html(temp);
		bck.show();
	}
	else
	{
	$(this).siblings("#VIDEOWMV").show();

	pplayer.controls.play();
	}
}


/*Player*/

$(document).ready(function(){
	var h2=$("div#textSupPlayer").height();
	
	if(h2>220)
	{
		$("div#textSupPlayer").css("height","220px").css("overflow-y","scroll");
	}
});


