/*globals $*/

// jQuery.preloadImages = function() {
// 	for(var a=0;a<arguments.length;a++) { 
// 		jQuery("<img>").attr("src",arguments[a])
// 		}
// 		};
		
var initTop = 200;
var initLeft = 370;
var divOnCenter = false;
var beerDivs = { 
		exoticas: { top:initTop,left:initLeft },
		luna: { top:initTop+110, left:initLeft-200 },
		coronel: { top:initTop+110,left:initLeft+200 },
		mediterranea: { top:initTop+380,left:initLeft-200 },
		coyote: { top:initTop+380,left:initLeft+200 },
		santa_fe: { top:initTop+460,left:initLeft } };
	
var seasonalBeerDivs = {
		ale:{ top:initTop+220,left:initLeft-300 },
		blueberry: {top:initTop+220,left:initLeft+300 }};
		
$(function() {
	
	$("a.exoticas, a.santa_fe, a.mediterranea, a.luna, a.coyote, a.coronel").click(function() { 
		var e = $(this).parent();
		var d = $(this).attr("class");
		
		// if there is an image on the center, return it to its original position
		if(divOnCenter!==false) {
			$("#"+divOnCenter+"-img").animate({top:beerDivs[divOnCenter].top,left:beerDivs[divOnCenter].left});
		}
		
		$(e).animate({top:"350px",left:"370px"});
		$(".description").children().hide("slow");
		$("#"+d).show();
		divOnCenter=d;
		return false;
	});
		
	$("#seasonal a").click(function(){
		var e = $(this).parent();
		var d = $(this).attr("class");
		$("#seasonal .desc").hide();
		$("#seasonal-intro").hide();
		$("#"+d).show();
		return false;
	});	
	
	
	var c = location.pathname.substring(1);
	
	if(c) {
		if(c.substring(0,4)==="menu") $("li.pop-menu a").attr("class","active");
		else $('a[href$="'+c+'"]').parent().attr("class","active");
	} else {
		$('a[href="/"]').parent().attr("class","active");
	}
	
	 $(".title").before('<img src="/img/cebada-left.png" alt="" class="rgt" >');
	 $(".title").after('<img src="/img/cebada-right.png" alt="" class= "lft">');
	 

	
	$("#thumbs a").click(function() {
		$("#full img").hide();
		var d=$(this).attr("class");
		$("#"+d).show();
		return false;
	});
		
	$("#menu").hide();
	$("#show-menu").click(function() {
		if($("#menu").css("display")=="none")	{
			$("#menu").css("display","block");
			$(this).parent().addClass("active");
		}else{
			$("#menu").css("display","none");$(this).parent().removeClass("active");
		}
		return false;
	});
	
	$("#promos").cycle({fx:"scrollDown",timeout:6000,speed:500});
	$(".desc").hide();
	$("#bolsa_de_trabajo").hide();
	$("#nav.forms a").click(function() {
		$("#nav.forms a").removeClass("current");
		$("#bolsa_de_trabajo, #sugerencias, #cerveceria").hide("slow");
		$(this).addClass("current");
		var d=$(this).attr("rel");
		$("#"+d).slideDown("slow");return false;
	});
	
	$("#cultura").hide();
	$("#text #nav a").click(function() {
		$("#nav a").removeClass("current");
		$("#cultura, #historia").hide("slow");
		$(this).addClass("current");
		var d=$(this).attr("rel");
		$("#"+d).slideDown("slow");
		return false;
	});
	
	$(".pics").cycle({fx:"fade",timeout:7000,random:1});
	
	$.fn.fancyzoom.defaultsOptions.imgDir="/img/zoom/";
	$("table.restaurantes a").fancyzoom();
	
	var a=[];
	
	function b(e) { 
		var d=e+" .reqr";
		$(d).each(function(g) {
			var f=$.trim($(this).val());
			if(f.length===0){a.push(this);}});
			if(a.length===0){return true;}
			else{return false;}}
			
	$("#sugerencias-form").submit(function(){
		a=[];
		$("*").removeClass("field-with-errors");
		if(b("#sugerencias-form")){
			$("#sugerencias-message").show();
			return true;
			}else{
				$.each(a,function(){
					$(this).addClass("field-with-errors");});
					return false;
				}
		});
			
		$("#bolsa-form").submit(function(){
			a=[];$("*").removeClass("field-with-errors");
			if(b("#bolsa-form")){
				$("#bolsa-message").show();
				return true;
				}else{
					$.each(a,function(){
						$(this).addClass("field-with-errors");});
						return false;
					}
			});
			
		$("#cerveceria-form").submit(function(){
			a=[];
			$("*").removeClass("field-with-errors");
			if(b("#cerveceria-form")){
				$("#cerveceria-message").show();
				return true;
				}else{
					$.each(a,function(){
						$(this).addClass("field-with-errors");});
						return false;
						}
				});
				
		$("#name-input").focus();
		$("#state-select").change(function(){
			var d=$(this).val();
			if(d==="Otro"){$("tr.other").show();
			}else{
				$("tr.other input").val("");
				$("tr.other").hide();
			}});
			
});
			
			
			
			
			
			
			
			
			
			
			
			
			
			
