// JavaScript

$(document).ready(function() {
						   
	$("#indice").attr('value',1);
	//Works				
	$(".contWorks a").click( function() { 
		url = this.href;
		$(".caseWorkPng").animate({"top": "-=500px"}, "slow", function (){
			$("#caseLoader").load(url);
			$("#caseLoader").css("top","190px");
			
			});
		//$('.caseWorkPng').show();
		return false;
		
	} );
	
	//HOME	aP
	/*
	$(".home_ap").bind("mouseenter", function(event){
		$(".home_ap_datos").show('slow');
		//$(".home_ap_datos_bg").show('slow');
	});
	$(".home_ap").bind("mouseout", function(event){
		$.timer(10000, function (timer) {
			$(".home_ap_datos").hide('slow');
			$(".home_ap_datos_bg").hide('slow');
			//alert("adios");
			timer.stop();
		});
	});
	*/
	
	//video home	
	/*
	$(".video_controls a").click( function() { 
		$(".video").toggle();
		return false;
		
	} );
	*/
	
	$("#videonext").click( function() { 

		puntero = $("#indice").attr('value');
		total = $(".video").length;
				
		$("#video_home_"+puntero).hide();
		
		if (puntero < total ){
			$("#indice").attr('value',(parseInt(puntero)+1))
			puntero = $("#indice").attr('value');

		}else{
			puntero = 1;	
			$("#indice").attr('value',1);
			puntero = $("#indice").attr('value');
		}
		$("#video_home_"+puntero).show();
		
		return false;

	} );
	
	$("#videoprev").click( function() { 

		puntero = $("#indice").attr('value');
		total = $(".video").length;
				
		$("#video_home_"+puntero).hide();
		
		if (puntero > 1 ){
			$("#indice").attr('value',(parseInt(puntero)-1))
			puntero = $("#indice").attr('value');

		}else{
			puntero = total;	
			$("#indice").attr('value',total);
			puntero = $("#indice").attr('value');
		}
		$("#video_home_"+puntero).show();
		
		return false;

	} );
	
	
	
	//linevent	
	/*
	$(".linevent").click( function() { 
		$(".events").toggle();
		return false;
		
	} );
	*/
	
	$("#year").change( function() { 
		$('.carr_all').hide();
		$('#carr_'+this.value).show();		
	} );
	
	
	$("#actos").change( function() { 
		$('.box_gris').hide();
		$('#'+this.value).show();		
	} );
	

	$("#eventnext").click( function() { 
		i = 0;
		//alert($(".events").size());
		$(".events").each(function(){			
			if($(this).css('display') == 'block'){
				txt = this.id;
				txt = txt.split("_")[1];
				$(this).hide();
			}
		  });
		
		txt = (parseInt(txt)+1);
		if(txt <= $(".events").size()){
			txt = '#evento_'+txt;
		}else{
			txt = '#evento_1';
		}
		$(txt).show();
	} );
	
	$("#eventprev").click( function() { 
		$(".events").each(function(){			
			if($(this).css('display') == 'block'){
				txt = this.id;
				txt = txt.split("_")[1];
				
				$(this).hide();
			}
		  });
		
		txt = (parseInt(txt)-1);
		if(txt >= 1){
			txt = '#evento_'+txt;
		}else{
			txt = '#evento_'+ $(".events").size();
		}
		$(txt).show();
	} );


	$("#YearSelect").change( function() { 
		window.location.href = '/sala/newsletter/' + ($(this).val()); 
	} );


});


 // Funcion AJAX para el registro del newsletter
 function ajaxnewsletter() {
	$.ajax({
		type: "POST",
		url: "/registro-news/",
		data: 'email=' + $('#form_email #email').val(),
		success: function(html)
		{
			$('#result_email').html(html);
			$("#form_email #btnAceptar").show();
		}
	});

	  
 }
 
 
 
 function Buscador(){
	window.location="/buscar/"+$("#SearchTxt").attr('value');
	}

 function Search(){
	window.location="/search/"+$("#SearchTxt").attr('value');
	}
	
	
