
function despliegaPreguntas(){
	if ($(".abrePreguntas").length) {	
		$('.abrePreguntas').click(
			function(){
				$('#preguntas').css('display', 'block');	
				return false;
			}			
		);
		$('#preguntas a.cerrar').click(
			function(){
				$('#preguntas').css('display', 'none');	
				return false;
			}			
		);
	}
}


function carrusel(){
	if ($("#vcarousel").length) {	
		jQuery('#vcarousel').jcarousel({
			vertical: true,
			scroll: 1
		});
	}
	if ($("#hcarousel").length) {	
		jQuery('#hcarousel').jcarousel({
			vertical: false,
			scroll: 3
			
		});
	}
}


function seleccionaPais(){
	if ($(".paises").length) {
		$(".paises").hide();
		$(".paises:first").show();
		$("#inicialesPaises a").click(
			function(){
				var pais = $(this).attr("href");
				$(".active").removeClass("active");
				$(this).addClass("active");
				$(".paises").hide();
				$(pais).show();
				return false;
			}							  
		);
	}
}

//Lightbox fotos	
function galeriaLightbox(){
	if ( $("a[rel^='prettyPhoto']").length) {					   
		$("a[rel^='prettyPhoto']").prettyPhoto({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 20, /* padding for each side of the picture */
			opacity: 0.60, /* Value betwee 0 and 1 */
			showTitle: false, /* true/false */
			allowresize: false, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			hideflash: true,
			theme: 'dark_square' /* light_rounded / dark_rounded / light_square / dark_square */
		});
	}
}
//Comprobamos la edad
function comprobarEdad(){
	$.ajax({
		type: "GET",
		url: "/ajax/controlEdad.php",
		success: function(msg){
			if(msg != "true"){
				GB_show("", "/control-edad.php",492,614);
				return false;
			}
		}
	});
}

function galeriaIndex(){
	
	$('.gallery a').css('opacity',0.3);
	
	var i = 0;
	$('.gallery a').each(function(){
		$(this).addClass("libimg"+i);				  
		i=i+1;
	});
	
	imgNum = i -1;
	
	$('.gallery a').click(function(){
								   
		currentImg = ($(this).attr("class").replace("libimg", ""))*1;
		gotoImgItem(this);		
		return false;
	});
	
	 gotoImgItem($(".libimg0"));
}

function gotoImgItem(el){
	clearTimeout(imgTimer);
	imgTimer = setTimeout("timedCount()",5000);
	
	$('.gallery a').fadeTo('slow', 0.5);
	$(el).fadeTo('slow', 1);
		
	$('#main_image img').hide();
	$('#main_image img').fadeIn('slow');
	$('#main_image img').attr("src", $(el).attr("href"));
	//Comento la siguiente linea porque ahora no quieren que las imágenes se abrán en un lightbox, sino que vayan a una página interior. Si desean volver a abrir el lightbox basta con descomentar esta línea y al enlace añadirle la clase "pretyPhoto"
	//$('#main_image a').attr("href", $(el).attr("href").replace("/img/all/home/eventos_anteriores/miniaturas/", "/img/all/eventos_anteriores/2009/lightbox/"));
}

function timedCount(){
	currentImg = currentImg + 1;
	
	if(imgNum < currentImg){
		currentImg = 0;
	}
	
	gotoImgItem($(".libimg"+currentImg));
	//alert(".libimg"+currentImg);
}

//llamamos a las funciones

$(document).ready(function () {
							
	if(document.getElementById("main_image") != null){
		galeriaIndex();
	}

	if(document.getElementById("controlEdadPagina") == null){
		comprobarEdad();
	}
	
	/*$(document).mousemove(function(e){
		var lPositionPercent = e.pageX/$(document).width();
		var lPosition = ($(document).width()-1208)/2;
		$('#misc_bg1').css("left", (lPosition + ((400*lPositionPercent)/3))+"px");
		$('#misc_bg3').css("left", (lPosition - ((100*lPositionPercent)/2))+"px");
		$('#misc_bg2').css("left", (lPosition + (150*lPositionPercent)/2)+"px");
		
		//$('#misc_bg1').css("left",(((100-lPosition)/2))+"%");
		//$('#misc_bg3').css("left",lPosition+"%");
		//$('#misc_bg2').css("left",((lPosition/2))+"%");
   	});*/
	
	var lPosition = ($(document).width()-1208)/2;		
	$('#misc_bg1').css("left", lPosition+"px");
	$('#misc_bg3').css("left", lPosition+"px");
	$('#misc_bg2').css("left", lPosition+"px");
	
	
	despliegaPreguntas();
  	seleccionaPais();
  	carrusel();
  	galeriaLightbox();
	
});

var GB_ANIMATION = true;

var currentImg = 0;
var imgTimer;
var imgNum = 0;