

/*---------------------------------------------------------Orçamento Online---------------------------------------------------------*/
$(function() {	
	$('<div id="mascara"></div>')
	.css({
		opacity : 0.8,
		width : $(document).width(),
		height : $(document).height()
	})
	.appendTo('body').click(function(){
		$(this).hide();
		$('#cadastre_popup').hide();
	}).hide();
	$('#cadastre_popup').hide();
	$('#orcamento').click(function(){		
		$('#cadastre_popup').show();
		$('#mascara').show();
		$('#nome_orcamento').focus();
	});
	$('.fechar').click(function(){
		$('#cadastre_popup').hide();
		$('#mascara').hide();
	});
});

$(function(){
	$('#enviarOrcamento').click(function(){
		var adultos = parseInt($('#adultos').val());	
		var criancas = parseInt($('#criancas').val());
		
		var total = adultos + criancas/2+0.5;
		if(!isNaN(adultos)){
			if(adultos < 25){
				alert("Numero de adultos deve ser maior que 25 pessoas.");
				document.form_cadastro.adultos.focus();
				return false;
			}
			else{
				if(validaEmail()){					
					document.form_cadastro.pessoa.value = total;
					document.form_cadastro.submit();
					return true;						
				}
			}
		}else{
			alert('Informe um numero de adultos maior que 25 pessoas.');
			document.form_cadastro.adultos.focus();
		}
		return true;		
	});
})

/*---------------------------------------------------------Lista retratil---------------------------------------------------------*/
$(function(){
	$('.lista1 li ul').hide();
	
	var hash = window.location.hash;	
	if(hash != ""){
		$(hash).next().slideToggle(1);
		$(hash).parent('li').siblings().children('ul:visible').hide();
	} else {
		$('.lista1 li ul:first').show();		
	}

	$('.lista1 li h4').css('cursor','pointer').click(function(){
		$(this).next().slideToggle(1);
		$(this).parent('li').siblings().children('ul:visible').hide();
	});

	/*
	
	$('.lista1 li ul').hide();
	$('.lista1 li ul:first').show();
	$('.lista1 li h4').css('cursor','pointer').click(function(){
		$(this).next().slideToggle(1);
		$(this).parent('li').siblings().children('ul:visible').hide();
	});

	*/
});

/*-------------------------------------------------------Colocar uma descricao em cada foto-----------------------------------------*/
$(function(){	
	$('#datas ul li img').each(function(i){
		var largura = $(this).css('width');
		var foto = $('<div class="left foto_bairro"></div>').css('width',largura);						
		var p  = $('<p>'+$(this).attr('alt')+'</p>'); 
		$(this).wrap(foto).after(p);						
	});
})

$(function(){	
	$('#datas2 ul li img').each(function(i){
		var largura = $(this).css('width');
		var foto = $('<div class="foto_bairro" align="center"></div>').css('width',largura);						
		var p  = $('<p>'+$(this).attr('alt')+'</p>'); 
		$(this).wrap(foto).after(p);						
	});
})

/*-------------------------------------------------------Mapa do Contato -------------------------------------------------------*/
$(function() {	
	$('<div id="mascara"></div>')
	.css({
	opacity : 0.8,
	width : $(document).width(),
	height : $(document).height()
	})
	.appendTo('body').hide();	
	$('#mapa a').click(function(event){
		event.preventDefault();								
		var filial = '<iframe width="630" height="480" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.br/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=Rua+Desembargador+Ot%C3%A1vio+do+Amaral,+827,+Merc%C3%AAs,+Curitiba+-+Paran%C3%A1&amp;sll=-14.179186,-50.449219&amp;sspn=83.621794,186.152344&amp;ie=UTF8&amp;hq=&amp;hnear=R.+Des.+Ot%C3%A1vio+do+Amaral,+827+-+Bigorrilho,+Curitiba+-+Paran%C3%A1,+80710-620&amp;ll=-25.42816,-49.295311&amp;spn=0.009302,0.013497&amp;z=16&amp;iwloc=A&amp;output=embed"></iframe>';

		$(filial).appendTo('.inner_map');
		$('#mascara').show();
		$('#mapa_popup').show();
		$('#mapa_popup').appendTo('body').show();		
	});
	$('#fechar').css('cursor','pointer').click(function(){
		$('.inner_map').empty();
		$('#mapa_popup').hide();
		$('#mascara').hide();
	});
});
/*----------------------------------------------------------- Instalacoes fancybox -----------------------------------------------------------*/
$(function(){	
	$('.instalacoes a').fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000'
	});	
	$('.slideshow a').fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000'
	});	
});

/*-----------------------------------------------------------Foto dos Assados-----------------------------------------------------------*/

$(function(){
	
	$('#lista_produtos li a').each(function(i){
		var $img = $(this).attr('href');
		var $title = $(this).attr('title');
		$('<a href="'+$img+'" title="'+$title+'"><img src="'+$img+'" width="300"/></a>').appendTo('#foto_produtos div').hide();
		
		$('#foto_produtos a:eq(0)').css('z-index','10').show();
		$(this).mouseover(function(){
			$('#foto_produtos a').hide().css('z-index',i);
			$('#foto_produtos a:eq('+i+')').css('z-index',i+1).show();
		});
	});

	$("#lista_produtos a, #foto_produtos a").fancybox({
		'overlayOpacity'	:	0.7,
		'overlayColor'		:	'#000'
	});	
});

/*----------------------------------------------------------- Produtos -----------------------------------------------------------*/
$(function(){
	var mousex = 0;
	var mousey = 0;	
	var balao = $('<div class="balao"><h3>Cortes Tradicionais</h3></div>').appendTo('body').hide();
	$("html").mousemove(function(mouse){
		mousex = mouse.pageX;
		mousey = mouse.pageY;
	});
	
	$("#produtos_icone li a").hover(
		function(){
			var tooltip = $(this).children().attr('alt');
			balao.show();
			$('.balao h3').empty().text(tooltip);
		},
		function(){
			$('.balao').hide();		
		}
	);	

	$("#produtos_icone li a").mousemove(function(mouse){
		var largura = $('.balao').width();
		var posicao_x = $(this).offset().left;		
		var largura_html = $('html').width();

		if(posicao_x+largura+150<largura_html){
			$(".balao").css({
				'left':mouse.pageX -10,
				'top':mouse.pageY - 50
			}).removeClass('balao_dir').addClass('balao_esq');
		}
		else{
			$(".balao").css({
				'left':mouse.pageX - largura + 30,
				'top':mouse.pageY - 50
			}).removeClass('balao_esq').addClass('balao_dir');
		}
	});	
});
/*Produtos full*/
$(function(){
	var url = window.location.hash;
	if(url==null || url==""){
		url = "#cortes_tradicionais";
	}
	$('#cortes_domakoski div').hide();
	$(url).show();

	$('<strong><a href="produtos.php" class="right">Voltar &raquo;</a><strong>').appendTo('#cortes_domakoski');
});


/*-----------------------------------------------------------  Receitas - carregamento por ajax ----------------------------------------------------------- */

function validaEmail(){
	var email  = document.forms[0].email_contato.value;
	var BadChars = "*|,\":<>[]{}`\'';()&$#% ";
	var GoodChars = "@.";
	var posarroba = email.indexOf ('@',0);
	if (email.length < 6) // o email é menor que 6 caracteres
	{
		alert("\"E-mail\" invalido!");	
		document.form_contato.email_contato.focus();
		document.form_contato.email_contato.focus();
		return (false);
	}
	for (var i = 0; i < email.length; i++)
	{
		if (BadChars.indexOf(email.charAt(i)) != -1) // Contém caracteres invalidos, badchars
		{
		alert("Seu \"E-mail\" contém caracteres invalidos!");
		document.form_contato.email_contato.focus();
		return (false);
		}
	}
	for (var i = 0; i < GoodChars.length; i++)
	{
		if (email.indexOf(GoodChars.charAt(i)) == -1) // não tem goodchars
		{
			alert("\"E-mail\" invalido!");
			document.form_contato.email_contato.focus();
		return (false);
		}
		if (email.indexOf(GoodChars.charAt(i),0) == 0) // começou com goodchars (. ou @)
		{
			alert("\"E-mail\" invalido!");		
			document.form_contato.email_contato.focus();
		return (false);
		}
		if (email.lastIndexOf(GoodChars.charAt(i)) > email.length-3) //existe menos de 2 caracteres depois do ultimo goodchar
		{
			alert("\"E-mail\" invalido! terminou com goodchars");		
			document.form_contato.email_contato.focus();
		return (false);
		}
	}
	if (email.lastIndexOf('@') > email.lastIndexOf('.')) //Não tem ponto depois do arroba
	{
		alert("\"E-mail\" invalido!");		
		document.form_contato.email_contato.focus();
		return (false);
	}
	
	if (email.indexOf ('@.',0) != -1 || email.indexOf ('.@',0) != -1) // . e @ colados
	{
		alert("\"E-mail\" invalido!");	
		document.form_contato.email_contato.focus();
		return (false);
	}
	if (email.indexOf ('@',posarroba+1) != -1) // Contém mais de um " @ "
	{
		alert("\"E-mail\" invalido!");		
		document.form_contato.email_contato.focus();
		return (false);
	}
	return true
}

function isBranco(field) {	
	var i;
	if(field.value == null){
		return true;
	}
	for( i = 0; i < field.value.length; i++ )
		if( field.value.charAt( i ) != unescape("%20") )
			return false;
	return true;
}

