 
 var interior = false;
 var abierto = false;
 

 
 
 function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
		
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

function pararVideo() {

	var elVideo = getStyle(document.getElementById("video"), "visibility");

	if(elVideo=="visible") moogaloop.api_pause();
}

function cerrarTodo() {
	
			manejador(interior,"+");
			
			var videoFondo = document.getElementById("moogaloop");
			videoFondo.style.visibility = "hidden";
			
			var cierraVideo = document.getElementById("video");
			cierraVideo.style.visibility = "hidden";
			
			/*var quitarImagen = document.getElementById("imagen");
			quitarImagen.style.visibility = "hidden";*/
			
			var quitarTransicion = document.getElementById("slide");
			quitarTransicion.style.visibility = "hidden";
			
			var quitarCarrusel2 = document.getElementById("carrusel2");
			quitarCarrusel2.style.visibility = "hidden";
			
			var quitarCarrusel = document.getElementById("transicion2");
			quitarCarrusel.style.visibility = "hidden";
			
			
}
 
 
 function cerrar(){
							  
	$('#container').animate({	
		
		"right": "-=40em"
	}, 800, function() {
	// Animation complete.
	
	
	
		$('#destacado_p').animate({	
			"right": "+=18em"
		}, 800, function() {
		// Animation complete.
		
				
		});
	
	
	});
	
	
	
}

 
 
 function manejador(paramInterior,paramSentido) {
	 
			pararVideo();
			
			
	 
	 		if(paramInterior) $('#container').animate({"right": paramSentido + "=59em"}, 800, function() {
					
					var elVideo = getStyle(document.getElementById("video"), "visibility");
					
					//if(elVideo=="visible" && paramSentido == "-") moogaloop.api_play();
				
			}); 

			
			else $('#container').animate({"right": paramSentido + "=40em"}, 800);  
			
			var elAbrir = document.getElementById("abrir");
			if(paramSentido == "+") {
				elAbrir.style.display = "block";
				
			}
			else {
				
				 elAbrir.style.display = "none";
				 
			}
			
			var elRecoger = document.getElementById("recoger");
			if(paramSentido == "+") elRecoger.style.display = "none";
			else elRecoger.style.display = "block";
			
			 return false;
 }
 
 function cargaPagina(paramInterior,paramDestino) {


		if(paramInterior){
			
					abierto = false;
			
					$('#container').animate({	
					
						
						"right": "-=59em"
		
		
					  }, 1000, function() {
						  
						
						//var laAltura = document.getElementById("altura");
						//laAltura.style.visibility = "hidden";
						  
						  $("#altura").load(paramDestino);
						  
					
						  
						  
						  $('#container').animate({	
						  
		
							"right": "+=59em"

		
					  }, 1000, function() {
						  
						 
							abierto = true;
							

							
					
					});		
				});	
		 
			}
			
			
			else {
				
				
				var elementAbierto = getStyle(document.getElementById("abrir"), "display");
				if(elementAbierto=="block") {
					
					abierto = false;
					
					
					$('#container').animate({	
		
					"right": "-=40em"
					}, 1000, function() {

						
					
					});
					
				}

				//var laAltura = document.getElementById("altura");
				//laAltura.style.visibility = "hidden";
				
				$('#container').animate({
										  
					"right": "+=40em"	
								
				},1000,function() {
					//Animación completada
					
					
					abierto = true;
					$("#altura").load(paramDestino);
					
				
					
				});
				
				
				
				var elDestacado = document.getElementById("destacado_p");
				elDestacado.style.visibility = "hidden";
			
				
				var elAbrir = document.getElementById("abrir");		
				elAbrir.style.display = "block";
				var elRecoger = document.getElementById("recoger");
				elRecoger.style.display = "none";
				
				
				
				//return false; 
				
			}
			interior = true;
			
			var elDestacado = document.getElementById("destacado_p");
			elDestacado.style.visibility = "hidden";
			
			elDestacado.style.right = 0;
			
			return false; 
 }

 function irPortada(paramDestino) {
	 

	 if(interior){
		 
		 
		 
		 
		 $("#altura").load(paramDestino);
		 
		  $('#container').animate({	
		
						"right": "-=40em"
					}, 800, function() {
					// Animation complete.
					
					  
					
					var elAbrir = document.getElementById("abrir");		
					elAbrir.style.display = "none";
					var elRecoger = document.getElementById("recoger");
					elRecoger.style.display = "block";
					
					var elDestacado = document.getElementById("destacado_p");
					elDestacado.style.visibility = "visible";
			
			
					$('#destacado_p').animate({	
					"right": "+=18em"
				}, 800, function() {
					
					// Animation complete.
				
				
				});
			
			
		
					
					});
	
						  
						  
					
						  
						  
						/*  
	
			
					$('#container').animate({	
						
						"right": "-=59em"
		
		
					  }, 800, function() {
						  
						  // Animation complete.
						  $('#container').animate({	
		
							"right": "+=59em"
		
					
					
		
					  }, 800, function() {
						  
						  // Animation complete.
						  
					
						  
					$("#altura").load(paramDestino);
					
					
					 $('#container').animate({	
		
						"right": "-=40em"
					}, 800, function() {
					// Animation complete.
					
					  
					
					var elAbrir = document.getElementById("abrir");		
					elAbrir.style.display = "none";
					var elRecoger = document.getElementById("recoger");
					elRecoger.style.display = "block";
					
					var elDestacado = document.getElementById("destacado_p");
					elDestacado.style.visibility = "visible";
			
			
					$('#destacado_p').animate({	
					"right": "+=18em"
				}, 800, function() {
					
					// Animation complete.
				
				
				});
			
					
					});
					 
					 	
					});
					
				});*/
				
				
		 
			}
			
			
			interior = false;
		
			
			return false;
				
		}


 
 //A PARTIR DE AQUÍ SE RECOGEN LOS CLICKS
 
 
 $(document).ready(function(){
	 
	// QueryLoader.selectorPreload = "#columns";
	
	if(!document.getElementById("siportada")) {
		interior = true;
		
	}
	
	//var elVideo = document.getElementById("video");


	$("#recoger").click(			   
		function(){
			//var laImagen = getStyle(document.getElementById("imagen"), "visibility");	
			var elVideo = getStyle(document.getElementById("video"), "visibility");
			var laTransicion = getStyle(document.getElementById("slide"), "visibility");
			var elCarrusel = getStyle(document.getElementById("transicion2"), "visibility");
			
			//if(elVideo=="visible" || laImagen=="visible" || laTransicion=="visible" || elCarrusel=="visible") cerrarTodo();
			if(elVideo=="visible" || laTransicion=="visible" || elCarrusel=="visible") cerrarTodo();
			else manejador(interior,"+");
		}
	);
		
		
	$("#abrir").click(
			
			function(){
				
				manejador(interior,"-");
			}

	
	);
	
	

								 
	$("#destacado_p").hover(
								 
								 
		function(){
			
			
			var elementWidth = getStyle(document.getElementById("destacado_p"), "width");
				
			if(elementWidth!="615px") {	
			
				$('#destacado_p').animate({
										  
					  
					  width: "615px"
					  
					  }, 800); 
			
			}
		},
		
		//Éste es el hover fuera
		function() {
			var elementWidth = getStyle(document.getElementById("destacado_p"), "width");
			
			if(elementWidth=="615px") {
				$('#destacado_p').animate({
										  
					  
					  width: "400px"
					  
					  }, 800);
			}
		}
	
	);
	
	
	
	$("#desaparecer").click(		   
		function(){
			
			var elDestacado = document.getElementById("destacado_p");
			elDestacado.style.visibility = "hidden";
			

		}
	);
	
	$("#cerrarVideo a").click (
		function(){		
			
			cerrarTodo();


		}
	);
	
	

	/*$("#cerrarImagen a").click(		   
		function(){
			
			cerrarTodo();
		
			
		}
	);*/

	$("#cerrarAmpliar a").click(		   
		function(){
			
			cerrarTodo();
		
			
		}
	);
	
	$("#cerrarCarrusel a").click(		   
		function(){
			
			cerrarTodo();
		
			
		}
	);
	
	
	//ENLACES
	
	/*$('#hizkuntza ul li a').click(function(){
		var toLoad = $(this).attr('href') + '&detalle=1';
		 $("#cuerpo").load(toLoad);
		 
		return false;
		});*/

	
	$('#menu ul li a.familia').click(function(){
											  
		pararVideo();
	
		
		var toLoad = $(this).attr('href') + '&detalle=1';
		//$.historyLoad(toLoad);
		var aDonde = $(this).attr('href').split("?")[0];
		if(aDonde=="/index.php") irPortada(toLoad);
		else cargaPagina(interior,toLoad);
		return false;
	});
	
	$('#menu ul li a.subfamilia').click(
	function(){
		
		pararVideo();


		var animarCapa = $(this).attr('href');
		$(animarCapa).animate({
					"left": "-=18em"
					}, 800, function() {
					// Animation complete		
		});									 										 
		return false;
		
	});
	
	$('#menu ul li div.ruta_menu a').click (
	function(){	
													
		pararVideo();
													
		var capas = $(this).attr('href').split("-");
		
		for(x=0; x<capas.length; x++){
			$(capas[x]).animate({
						"left": "+=18em"
						}, 800, function() {
						// Animation complete		
			});	
		
		
		}
		
		return false;

	});

	
	$('#pie ul li a').click (
	function(){	
			pararVideo();
			var toLoad = $(this).attr('href') + '&detalle=1';
			cargaPagina(interior,toLoad);
			return false;
	});
	
	$('#rss a').click (
	function(){	
			pararVideo();
			var toLoad = $(this).attr('href') + '&detalle=1';
			cargaPagina(interior,toLoad);
			return false;
	});
	
	/*$('ul#linkportada li a').click (
	function(){	
			pararVideo();
			var toLoad = $(this).attr('href') + '&detalle=1';
			cargaPagina(interior,toLoad);
			return false;
	});*/
	
	$('h1 a').click(function(){
		
		pararVideo();
		
		var toLoad = $(this).attr('href') + '&detalle=1';
		irPortada(toLoad);
		return false;
		
	});
	
	
	
	
    
});
 
 














