$('document').ready(function(){
	$("#loader").hide();
	$("#loader").ajaxStart(function(){
		$(this).show();
	});							
	$("#loader").ajaxStop(function(){
		$(this).hide();
	});							
});

function carrega_cardapio(qual){
	$.getJSON("cardapio/"+qual+".txt?noob="+ new Date().getTime(), function(json){
		$("#menu_cardapio li").show();
		$("#menu_cardapio #"+qual).toggle();
		$("#cardapio").toggle("fast");
		var cardapio = "<h2><img src='img/tit_"+qual+".jpg' /><h2>";
		var prato = "";
		var receita = "";
		$.each(json.itens, function(i,item){
			prato = String(item.prato);
			receita = String(item.receita);
			cardapio = cardapio + "<h3>"+prato+"</h3><h4>"+receita+"</h4>";			
		});
		$("#cardapio").html(cardapio);
		$("#cardapio").toggle("fast");
	});
	
}

function carrega_curiosidades(qual){
	$.getJSON("curiosidades/"+qual+".txt?noob="+ new Date().getTime(), function(json){
		$("#menu_curiosidades li").show();
		$("#menu_curiosidades #"+qual).toggle("fast");
		$("#curiosidades").toggle("fast");
		$("#detalhe_curiosidades").html("<img src='img/curiosidades_"+qual+".jpg' />");
		$("#fotos_curiosidades").toggle("fast");
		var curiosidades = "<h2><img src='img/tit_"+qual+".jpg' /><h2>";
		curiosidades = curiosidades + "<h4>"+json.texto+"</h4>";
		var thumb = "";
		var imagem = "";
		var imgs = "";
		$.each(json.imagens, function(i,item){
			thumb = String(item.thumb);
			imagem = String(item.imagem);
			imgs = imgs + "<a href='img/"+imagem+"'><img src='img/"+thumb+"' /></a>";			
		});
		$("#curiosidades").html(curiosidades);
		$("#fotos_curiosidades").html(imgs);
		$("#curiosidades").toggle("fast");
		$("#fotos_curiosidades").toggle("fast");
		$('#fotos_curiosidades a').lightBox();
	});	
}

function valida_newsletter(){
	var nome = document.getElementById("nome");
	var email = document.getElementById("email");

	if(nome.value.replace(/[ ]+/g,"").replace(/\r\n/g, "")== ""){
		alert("O nome deve ser preenchido!");
		nome.focus();
		return false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)){
	}else{
		alert('O E-mail deve ser preenchido corretamente!');
		email.focus();
		return false;
	}
}
var options = {
	beforeSubmit: valida_newsletter,
    success: function(msg) {		
        $('#newsleter').empty();
    	$("#newsleter").html(msg);
    }
};
function Envia_Newsletter(){
	$('#form_newsletter').ajaxSubmit(options);
}

function valida_contato(){
	var nome = document.getElementById("nome");
	var email = document.getElementById("email");
	var msg = document.getElementById("msg");

	if(nome.value.replace(/[ ]+/g,"").replace(/\r\n/g, "")== ""){
		alert("O nome deve ser preenchido!");
		nome.focus();
		return false;
	}
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)){
	}else{
		alert('O E-mail deve ser preenchido corretamente!');
		email.focus();
		return false;
	}
	if(msg.value.replace(/[ ]+/g,"").replace(/\r\n/g, "")== ""){
		alert("A Mensagem deve ser preenchido!");
		msg.focus();
		return false;
	}
}
var option = {
	beforeSubmit: valida_contato,
    success: function(msg) {		
        $('#contato').empty();
    	$("#contato").html(msg);
    }
};
function Envia_Contato(){
	$('#form_contato').ajaxSubmit(option);
}
