$(document).ready(function(){
	/**
	   * Acessibilidade
	   **/
	$('.bt-voltar, #bt-contato').css("cursor", "pointer");
	$('.bt-voltar').click(function(){
		history.go(-1);
	});	
	$('#bt-imprimir').click(function(){
		window.print();
	});

	/**
	   * Flash
	   **/
	$('#header').flash({
	    src: 'swf/header.swf',
	    width: '100%',
	    height: 830,
		wmode: 'transparent',
		expressInstall: true
	});
	$('#header-internas').flash({
	    src: 'swf/header-internas.swf',
	    width: '100%',
	    height: 830,
		wmode: 'transparent',
		expressInstall: true
	});
	
	$('.flash-pop').flash({
	    src: 'swf/banner-pop.swf',
	    width: 1024,
	    height: 760,
		wmode: 'transparent',
		expressInstall: true
	});
	
	$(".linkezor").click(function(){
		return false;
	});

	/**
	   * Links externos
	   **/
	$("a[rel=externo]").attr('target','_blank');

	/**
	   * Ativa as tabs
	   **/
	$(".tabs").tabs();

	/**
	   * Opacidade
	   **/
	$(".opac").css("opacity","0.5");
	
	/**
	   * Thumbs
	   **/
	$(".thumb img").hover(
		function(){ $(this).css({opacity:"0.3"}) },
		function(){ $(this).css({opacity:"1"}) }
	);

	/**
	   * Cycle galeria de fotos
	   **/
	$(".holder").cycle({ 
	    fx: "scrollHorz", 
	    prev: ".bt-esquerda", 
	    next: ".bt-direita", 
	    timeout: 0 
	});
});

/**
  * Função Validar Formulário
  * @param form identificador do formulario
  * @return Boolean
  **/
function validaForm(form) {
    for (var i = 0; i < document.getElementById(form).elements.length; i++) {        
        var nomeObj = document.getElementById(form).elements[i].name;
        var idObj 	= document.getElementById(form).elements[i].id;
		var relObj 	= document.getElementById(form).elements[i].getAttribute('rel');				
		if ((relObj == "email")) {
			expressao = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/i;
			if (!expressao.test(document.getElementById(form).elements[i].value)){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].value = "";
				document.getElementById(form).elements[i].focus();
				return false;
			}
		} else if (relObj == "required") {
			if((document.getElementById(form).elements[i].value == null) || (document.getElementById(form).elements[i].value == "")){
				alert(document.getElementById(form).elements[i].title);
				document.getElementById(form).elements[i].focus();
				return false;
			}
		}
    }
    return true;
}

/**
  * Função Validar contato
  * @param 
  * @return nada
  **/
function validarContato() {
	if (validaForm('formContato')) {	
		var str = $("#formContato").serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao_contato.php",
			data: str,
			beforeSend: function() {
			},
			success: function(txt) {
				alert("Mensagem enviada com sucesso! Obrigado!");
				document.getElementById("formContato").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
  * Função Validar newsletter
  * @param 
  * @return nada
  **/
function validarNews() {
	if (validaForm('formNews')) {	
		$.ajax({
			type: "POST",
			url: "lib/acao_newsletter.php",
			data: "email=" + $("#email").val(),
			beforeSend: function() {
			},
			success: function(txt) {
				alert(txt);
				document.getElementById("formNews").reset();
			},
			error: function(txt) {
				alert('Erro: '+txt);
			}
		});
	}
}

/**
  * Função mostra galeria da home
  * @param 
  * @return nada
  **/
function showHome() {
	if ($(".box-galeria").css('display') == 'none') {	
		$(".box-galeria").slideDown('normal');
		$(".box-news").slideDown('normal');
		$(".box-promocoes").slideDown('normal');
	}
}

/**
  * Função troca foto
  * @param imagem
  * @param titulo
  * @return nada
  **/
function atualizaFoto(imagem, titulo) {
	document.getElementById("div_imagem").src = imagem;
	document.getElementById("div_imagem_titulo").innerHTML = titulo;
}

function fechaPop(){
	var divMae = document.getElementById("flash-pop-mae");
	var divFilha = document.getElementById("flash-pop");
	
	divMae.removeChild(divFilha);
}