var currentGalImgHome = 0;
var maxGalImgHome = 0;


$(function(){
	maxGalImgHome = $(".gal_animated").length;
	$("#container_ajax_btn_enter").animate({
		left: "-900px",
		opacity: 1
	},4000);
	$(".floatAnchor").lightBox();
	$("#contactForm").submit(function(){
							if(validacampos($(this))){
								return true;
							}else{
								return false;
							}
						});
	$("#menu_izquierdo a").click(function(){
		var url = $(this).attr("href");
		$("#menu_izquierdo a").removeClass("selected");
		$(this).addClass("selected");
		$.get(url,{},function(xml){
			var contenido = $("#container_info",xml).html();
			
			
			/*
			$("#container_info").fadeOut(800,function(){
				$(this).empty().html(contenido).fadeIn(800);
			});
			*/
			
			$("#container_info").animate({ 
			    right: "-900px"
			},800,function(){
				$(this).empty().html(contenido).animate({ 
				    right: "0px"
				},800,function(){
					if(url == "/galeria.html"){
						animateGal();
					}
					$(".floatAnchor").lightBox();
					if(url == "/contacto.html"){
						$("#contactForm").submit(function(){
							if(validacampos($(this))){
								return true;
							}else{
								return false;
							}
						});
					}
				});
				
			});
			
			
		});
		
		
		return false;
	});
	
	$(".leftArrow").click(function(){
		moveGal("rest",false);		
		return false;
	});
	$(".rightArrow").click(function(){
		moveGal("add",false);		
		return false;
	});	

});

function animateGal(){
	maxGalImgHome = $(".gal_animated").length;
			
	$(".leftArrow").click(function(){
		moveGal("rest",false);		
		return false;
	});
	$(".rightArrow").click(function(){
		moveGal("add",false);		
		return false;
	});	
}
function moveGal(action,soloUpdate){
	if(action == "add"){
		nCurrentImgHome = (currentGalImgHome * 1) + 1;
		if(nCurrentImgHome >= maxGalImgHome){
			currentGalImgHome = 0;
		}else{
			currentGalImgHome = nCurrentImgHome;
		}
	}else{
		nCurrentImgHome = (currentGalImgHome * 1) - 1;
		if(nCurrentImgHome <= 0){
			currentGalImgHome = maxGalImgHome;
		}else{
			currentGalImgHome = nCurrentImgHome;
		}		
	}	
	
	var curWidth = currentGalImgHome * 680;
	
	$("#ajaxGalInfinite").animate({
		left: "-" + curWidth + "px"	
	  }, 1000);	
}
function sendForm(){
	$("#contactForm").submit();

	return false;
}
