
var tiempo = 8000;
var i = 1;
function rotar(){
	var totalImagenes = $("#fondos img").length;
	$("#fondos img:eq("+i+")").fadeIn().siblings().fadeOut();
	if(++i == totalImagenes)i = 0;
	setTimeout(function(){
		rotar();
	},tiempo);
}
$(function() { 
	$("#fondos img:eq(0)").show().siblings().hide();
	setTimeout(function(){
		rotar();
	},tiempo);
	$(".seccion:odd").addClass("odd");
	
	$(".seccion h2").click(function(){
		var parent =$(this).parent()
		if(!parent.hasClass("selected")){
			$(".logos").hide();
			parent.addClass("selected");
			var index = $(".seccion h2").index(this);
			var margin = index*(-43);
			var totalHeight = $(document).height();
			
			$(this).parent().parent().animate({marginTop:margin+"px"},500);
			$(this).parent().animate({height:totalHeight},500,function(){
				time = 0;
				cargar_fotos();
			});
		}else{
			$(this).parent().removeClass("selected");
			$(this).parent().parent().animate({marginTop:"0px"},500);
			$(this).parent().animate({height:"43px"},500);
		}
	});
	$(".seccion .cerrar").click(function(){
		$(this).parent().removeClass("selected");
		$(this).parent().parent().animate({marginTop:"0px"},500);
		$(this).parent().animate({height:"43px"},500);
		return false;
	});
	
	$("#footer li a").click(function(){
		$(".seccion.selected h2").click();
		var martini = $(this).attr("href");
		setTimeout(function(){
			$(martini).click();
		},700);
	});
	$(".form_contacto").hide();
	
	$(".titulo_contacto h3").click(function(){
		var obj = this;
		$(".form_contacto").hide();
		$("#"+$(obj).attr("rel")).stop().fadeIn("normal");
		$(this).addClass("selected").siblings().removeClass("selected");
	});
	$(".titulo_contacto h3:eq(0)").click();
	
	$("#formulario_contacto").submit(function(){
		msj = "";
		if($("#nombre1").val() == "")msj += "- Debe ingresar su nombre\n";
		if($("#apellido1").val() == "")msj += "- Debe ingresar su apellido\n";
		if($("#email1").val() == "")msj += "- Debe ingresar su email\n";
		if($("#comentario1").val() == "")msj += "- Debe ingresar algún comentario\n";
		if(msj != ""){
			alert("Se encontraron los siguientes errores:\n\n"+msj);
			return false;	
		}
	});
	
	$("#formulario_trabaja").submit(function(){
		msj = "";
		if($("#nombre2").val() == "")msj += "- Debe ingresar su nombre\n";
		if($("#rut2").val() == "")msj += "- Debe ingresar su rut\n";
		if($("#ciudad2").val() == "")msj += "- Debe ingresar su rut\n";
		if($("#apellido2").val() == "")msj += "- Debe ingresar su apellido\n";
		if($("#email2").val() == "")msj += "- Debe ingresar su email\n";
		if($("#comentario2").val() == "")msj += "- Debe ingresar algún comentario\n";
		if(msj != ""){
			alert("Se encontraron los siguientes errores:\n\n"+msj);
			return false;	
		}
	});
});
var time = 0;
function cargar_fotos(){
	$(".logos").each(function(){
		var obj = $(this);
		setTimeout(function(){
			obj.fadeIn("fast");
		},time);
		time = time + 100;
	});
}
$(function() {
	  $("input.file_1").filestyle({ 
          image: "img/btn_examinar.png",
          imageheight : 28,
          imagewidth : 110,
          width : 150
      });
});
