	
	var galerias_selected = 'galerias_fotogaleria';
	var pos_galerias_fotos_deldia;
	var pos_galerias_fotos_historico = 0;
	var audioPopup, fotosPopup, videosPopup;
	var autoplay;
	var videoGaleriaLoaded = -1;		
	var audioGaleriaLoaded = -1;
	var rotador_galeria_historico =	0;
	var auto_close_aviso = 0;

	function cerrar_aviso_layer() {		
		$("#aviso_layer").fadeOut("slow");
		clearInterval(auto_close_aviso);
	}
	
	function verificar_subsecciones(idsubseccion){
		var resultado = false;
		$.each($(".subseccion"), function() {
			if (($("img", this).attr("alt") == 1) && ($(this).attr("id") != idsubseccion)) {
				resultado = true;
			}
		});
		return resultado;
	}
	
	function verificar_notas_subsecciones(){
		var contador = 0;
		$.each($(".nota_seccion"), function() {
			if ($(this).is(':visible')) {
				contador++;
			}
		});
		return contador;
	}
	
	function nav_fotos_deldia(dir) {
		if (galerias_fotos_deldia.length > 0) {
			switch(dir) {
				case 0:
					pos_galerias_fotos_deldia = Math.floor(Math.random()*40);
					break;
				case 1:
					pos_galerias_fotos_deldia = pos_galerias_fotos_deldia + 1;
					if (pos_galerias_fotos_deldia > galerias_fotos_deldia.length - 1) {
						pos_galerias_fotos_deldia = 0;
					}
					break;
				case -1:
					pos_galerias_fotos_deldia = pos_galerias_fotos_deldia - 1;
					if (pos_galerias_fotos_deldia < 0) {
						pos_galerias_fotos_deldia = galerias_fotos_deldia.length - 1;
					}
					break;					
			}		
			$("#galerias_fotogaleria_foto .clip").html('<img src="'+galerias_fotos_deldia[pos_galerias_fotos_deldia]+'" height="190"/>');
			$("#galerias_fotogaleria_foto .epigrafe").html(galerias_fotos_deldia_epigrafes[pos_galerias_fotos_deldia]);
		}
	}
	
	function nav_historico(id, dir) {
		if (id == 'galerias_fotogaleria_historico') {
			clearInterval(rotador_galeria_historico);
		}
		switch(dir) {
			case 1:	
				var left_indent = parseInt($("#"+id+" ul").css("left")) - 280;
				$("#"+id+" ul:not(:animated)").animate({"left" : left_indent}, 500, function () {
					$("#"+id+" li:last").after($("#"+id+" li:first"));                 	
					$("#"+id+" ul").css({"left" : -280});	
				});
				break;			
			case -1:
				var left_indent = parseInt($("#"+id+" ul").css("left")) + 280;
				$("#"+id+" ul:not(:animated)").animate({"left" : left_indent}, 500,function(){ 	
					$("#"+id+" li:first").before($("#"+id+" li:last"));           
					$("#"+id+" ul").css({"left" : -280});
				});    
				break;
		}
	}	
	
	function rotar_gal_historico() {
		var left_indent = parseInt($("#galerias_fotogaleria_historico ul").css("left")) - 280;
		$("#galerias_fotogaleria_historico ul:not(:animated)").animate({"left" : left_indent}, 500, function () {
			$("#galerias_fotogaleria_historico li:last").after($("#galerias_fotogaleria_historico li:first"));                 	
			$("#galerias_fotogaleria_historico ul").css({"left" : -280});	
		});
	}
	
	function loadVideo(id, srv, cod) {
		if (videoGaleriaLoaded != id) {
			$("#video").html('<div id="video_embed"></div>');
			autoplay = true;
			loadVideoChannel(srv, cod);
			videoGaleriaLoaded = id;
		}
	}	

	function loadAudio(id, aud) {
		if (audioGaleriaLoaded != id) {
			var flashvars = { audio : aud }; 
			swfobject.embedSWF("multimedia/players/audioplayer.galeria.swf", "audio_embed", "280", "30", "8.0.0.0", "", flashvars);
			audioGaleriaLoaded = id;
		}
	}	
	
	function iniciar_busqueda_rapida(srv) {
		var consulta = $.trim($("#buscar_q").val());
		if (consulta.length > 2) {
			window.open("buscar.html?s="+srv+"&q="+consulta, "busquedarapida");
		}
		else {
			$("#menu_buscar .sub-menu").hide();
			$("#menu_buscar .mensaje").show();
		}
	}
	
	$(document).ready(function(){	
		$(".desplegable").hover(
			function () {
				$(".sub-menu", this).show();
			}, 
			function () {
				$(".sub-menu", this).hide();
			}
		);
		
		$(".desplegable").click(function() {
			if ($(this).attr("href") != undefined) {
				window.location = $(this).attr("href");
				return false;
			}
		});
		
		$("#menu_buscar .mensaje").hover(
			function () {
				$(this).show();
			}, 
			function () {
				$(this).hide();
			}
		);
		
		$(".item").click(function() {
			if ($(this).attr("href") != undefined) {
				window.location = $(this).attr("href");
				return false;
			}
		});

		$("#portada").click(function() {
			window.location = 'index.html?m=m';
			return false;
		});		
		
		$(".galeria").click(function() {
			var ileft = (screen.width - 639) / 2;
			var itop = (screen.height - 553) / 2; 		
			audioPopup = window.open("multimedia/?n="+$(this).attr("id"),"GALERIA","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left="+ileft+",top="+itop+",width=639,height=553");
			audioPopup.focus();
		});
		
		$(".video").click(function() {
			var ileft = (screen.width - 634) / 2;
			var itop = (screen.height - 582) / 2; 		
			videoPopup = window.open("multimedia/?n="+$(this).attr("id"),"VIDEOS","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left="+ileft+",top="+itop+",width=634,height=582");
			videoPopup.focus();
		});

		$(".audio").click(function() {
			var ileft = (screen.width - 466) / 2;
			var itop = (screen.height - 266) / 2; 		
			audioPopup = window.open("multimedia/?n="+$(this).attr("id"),"AUDIOS","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left="+ileft+",top="+itop+",width=466,height=266");
			audioPopup.focus();
		});
		
		$(".subseccion").click(function() {
			$("#mensaje_seccion").hide();
			if ($("img", this).attr("alt") == 1) {
				if (verificar_subsecciones($(this).attr("id")) == true) {
					$("img", this).attr("src", "css/img/subsecciones/no_"+$(this).attr("id")+".png")
					$("img", this).attr("alt", 0);
					$("."+$(this).attr("id")).hide();
				}
			}
			else {
				$("img", this).attr("src", "css/img/subsecciones/"+$(this).attr("id")+".png")
				$("img", this).attr("alt", 1);
				$("."+$(this).attr("id")).show();
			}

			if (verificar_notas_subsecciones() == 0) {
				$("#mensaje_seccion").show();
			}
		});
		
		$(".galerias_seccion").click(function() {
			if ($(this).attr("id") != galerias_selected) {
				switch($(this).attr("id")) {
					case 'galerias_fotogaleria':
						$("img", this).attr("src", "css/img/galerias/fotogaleria.png");
						$("img", "#galerias_videos").attr("src", "css/img/galerias/no_videos.png");
						$("img", "#galerias_audios").attr("src", "css/img/galerias/no_audios.png");
						break;
					case 'galerias_videos':
						$("img", this).attr("src", "css/img/galerias/videos.png");
						$("img", "#galerias_fotogaleria").attr("src", "css/img/galerias/no_fotogaleria.png");
						$("img", "#galerias_audios").attr("src", "css/img/galerias/no_audios.png");
						break;
					case 'galerias_audios':
						$("img", this).attr("src", "css/img/galerias/audios.png");
						$("img", "#galerias_fotogaleria").attr("src", "css/img/galerias/no_fotogaleria.png");
						$("img", "#galerias_videos").attr("src", "css/img/galerias/no_videos.png");						
						break;
				}
				galerias_selected = $(this).attr("id");
				$(".galerias_contents").hide();
				$("#"+galerias_selected+"_content").show();
			}
		});	
	});
	
	/*
	
		BANNER FLOTANTE
		
		************************************************************************
		* You may use this code for free on any web page provided that 
		* these comment lines and the following credit remain in the code.
		* Floating Div from http://www.javascript-fx.com
		************************************************************************ 
		 
		Modificaciones TopLimit, BottomLimit y Posición desde la Izquierda _ 2011-11-16 _ mt
	
	*/
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function FloatDiv(id, sx, sy, tl, bl) {
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		var px = document.layers ? "" : "px";
		window[id + "_obj"] = el;
		if(d.layers)el.style=el;
		el.cx = el.sx = sx;el.cy = el.sy = sy;
		el.tl = tl;
		el.bl = bl;
		el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

		el.floatIt=function() {
			var pX, pY;
			pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
			document.documentElement && document.documentElement.clientWidth ? 
			document.documentElement.clientWidth : document.body.clientWidth;
			pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
			document.documentElement.scrollTop : document.body.scrollTop;
			if(this.sy<0) 
			pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
			document.documentElement.clientHeight : document.body.clientHeight;
			this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
			if(this.cy<this.tl) {
				this.cy=this.tl;
			}
			if((this.cy + el.clientHeight)>this.bl) {
				this.cy=this.bl - el.clientHeight;
			}
			this.cx=document.getElementById("content").offsetLeft + 689;
			this.sP(this.cx, this.cy);
			setTimeout(this.id + "_obj.floatIt()", 40);
		}
		return el;
	}
