IncludeJavaScript("scripts/cufon.js"); // Núcleo do Cufón
IncludeJavaScript("scripts/fontes.js"); // Fontes
IncludeJavaScript("scripts/jquery.facebox.js"); // Facebox
IncludeJavaScript("scripts/jquery.lightbox.js"); // Lightbox
IncludeJavaScript("scripts/jquery.cycle.js"); // Cycle
IncludeJavaScript("scripts/jquery.easing.js"); // Easing
IncludeJavaScript("scripts/jquery.ui.js"); // jQuery UI completo
IncludeJavaScript("scripts/jquery.scrollto.js"); // Smooth Scroll na tela
IncludeJavaScript("scripts/jquery.maskedinput.js"); // Máscaras para formulários 
IncludeJavaScript("scripts/jquery.bg.js"); // Animação do Menu
IncludeJavaScript("scripts/jquery.form.js"); // Forms
IncludeJavaScript("scripts/jquery.multifile.js"); // Multi file

$(function() {
	
	// Links externos
	$("a[rel=external]").attr("target", "_blank");
	$("a[rel=external nofollow]").attr("target", "_blank");

	// Botoes
	$("input[type=submit]").css("cursor", "pointer");
	$("input[type=button]").css("cursor", "pointer");

	// Voltar
	$(".bt-voltar").click(function() { history.back(); return false; });

	// Transparencia
	setTimeout(function() { 
		$(".opac").css("opacity","0.6");
	},  1000);
	
	// Setas
	$(".fade").css("opacity", 0.5);
    $(".fade").hover(function() {
        $(this).fadeTo("normal", 1.0);
    },function() {
        $(this).fadeTo("normal", 0.5);
    });
	
	// Menu Nav
	var velAnim = 500; // Velocidade da animação
	var effectAnim = "easeOutBounce"; // Efeito da animação
	$("#nav li a").hover(function() {
		if(!$(this).hasClass("go-content")) {
			if(!$(this).hasClass("active")) {
				$(this).animate({backgroundPosition: "100% 0px"}, velAnim, effectAnim);
				$(this).find("span").animate({backgroundPosition: "0px 0px"}, velAnim, effectAnim);
			}
		}
	},function(){
		if(!$(this).hasClass("go-content")) {
			if(!$(this).hasClass("active")) {
				$(this).animate({backgroundPosition: "100% 55px"}, velAnim, effectAnim);
				$(this).find("span").animate({backgroundPosition: "0px 55px"}, velAnim, effectAnim);
			}
		}
	});
	
	// Topo
	$(".bt-topo").click(function() {
		$.scrollTo( { top:0,left:0 } , 500 );
		return false;
	});
	
	// Cufon
	Cufon.replace(".lobster", { fontFamily: "Lobster 1.2", hover: true });
	Cufon.replace(".lobster-gr", { fontFamily: "Lobster 1.2", color: "-linear-gradient(#ffffff, #bca506)", hover: { color: "-linear-gradient(#bca506, #ffffff)" } });
	Cufon.replace(".lobster-s", { fontFamily: "Lobster 1.2", textShadow: "#612300 1.5px 1.5px", hover: true });
	Cufon.replace(".garamond", { fontFamily: "Garamond", hover: true, ignore: { small: true } });
	Cufon.replace(".garamond-s", { fontFamily: "Garamond", textShadow: "#000 1.5px 1.5px", hover: true, ignore: { small: true } });
	Cufon.replace(".garamond-gr", { fontFamily: "Garamond", color: "-linear-gradient(#ffffff, #d2c359)", hover: true });
	
	// Cycle
	$(".box-holder ul").cycle({
		fx: "scrollHorz",
		easeIn: "easeInOutBack",
		easeOut: "easeInOutBack",
		prev: ".arrow-left",
		next: ".arrow-right",
		timeout: 0
	});	
	
	// Cycle
	$(".gira-destaques").cycle({
		fx: "fade",
		timeout: 4000,
		cleartypeNoBg:true,
		cleartype:true
	});
	
	// Cycle - Home
	$(".promocoes-diarias").cycle({
		fx: "scrollHorz",
		easeIn: "easeInOutBack",
		easeOut: "easeInOutBack",
		prev: ".arrooow-left",
		next: ".arrooow-right",
		timeout: 15000
	});
	
	// Destaques
	$("<div class='opac'></div>").insertBefore(".gira-destaques p");
	
	// Subtitulo
	$(".reservat").click(function() {
		var agaref = $(this).attr("href");
		$(".box-escolhe").removeClass("pagina-aberta");
		$(agaref).addClass("pagina-aberta");
		$(".box-escolhe").slideUp("500");
		$(agaref).slideDown("500");
		return false;
	});
	
	$("#subtitulos ul li a").click(function() {
		setTimeout(function() {
			var pegaPosicao = $(".bt-compartilhe").offset();
			$(".compartilhar").animate({"left":pegaPosicao.left - 415, "top":pegaPosicao.top}, velAnim, effectAnim);
		}, 1000);		
		if ($(this).hasClass("bt-como-chegar")) {
			$(".mapa").html('<iframe width="934" height="414" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com.br/maps/ms?source=s_q&amp;hl=pt-BR&amp;geocode=&amp;ie=UTF8&amp;hq=Pra%C3%A7a+Ol%C3%ADvio+Amorim&amp;hnear=Pra%C3%A7a+Ol%C3%ADvio+Amorim+-+Florian%C3%B3polis+-+Santa+Catarina&amp;msa=0&amp;msid=114506022231096283389.00048be62b284f0b1f493&amp;ll=-27.595041,-48.544743&amp;spn=0.007873,0.02002&amp;z=17&amp;iwloc=A&amp;output=embed"></iframe>');
		}		
		if ($("#subtitulos ul li a").hasClass("sel")) {
			$("#subtitulos ul li a").removeClass("sel");
			$(this).addClass("sel");
		} else {
			$(this).addClass("sel");
		}
		
		var agaref = $(this).attr("href");
		if (!$(agaref).hasClass("pagina-aberta")) {
			$(".box-escolhe").removeClass("pagina-aberta");
			$(agaref).addClass("pagina-aberta");
			$(".box-escolhe").slideUp("500");
			$(agaref).slideDown("500");
		}
		$("#subtitulos ul li a").removeClass('active');
		$(this).addClass('active');
		return false;
	});
	
	// Subtitulo - Alinhamento
	var largura = 0;
	$("#subtitulos ul li a, #subtitulos-2 ul li a").each(function() {
		largura += $(this).width();
	});
	$("#subtitulos ul, #subtitulos-2 ul").css("width", largura + 5);
	
	// Paginacao - Alinhamento
	var pagina = 0;
	$(".paginacao a").each(function() {
		pagina += $(this).width() +14;
	});
	$(".paginacao").css("width",pagina);
	
	// Redes Sociais
	$(".ico-redes").hover(function() { 
		var posicaoIco = $(this).css("backgroundPosition");
		var resultadoSplit = posicaoIco.split(" ");
		$(this).css("backgroundPosition",resultadoSplit[0] + " -33px");
	},function() {
		var posicaoIco = $(this).css("backgroundPosition");
		var resultadoSplit = posicaoIco.split(" ");
		$(this).css("backgroundPosition",resultadoSplit[0] + " 0px");
	});
	
	// Estiliza listas
	$(".lista li:even").addClass("even");
	$(".lista li:odd").addClass("odd");
	$(".lista li:first-child").addClass("first");
	$(".lista li:last-child").addClass("last");
	$(".paginacao a:last-child").addClass("last");
	
	// Compartilhe com um amigo
	$(".bt-compartilhe").click(function() {
		var pegaPosicao = $(".bt-compartilhe").offset();
		$(".compartilhar").css("left",pegaPosicao.left - 415).css("top",pegaPosicao.top).slideToggle("slow", effectAnim);
		return false;
	});
	
	// Alinhas compartilhamento caso mude a página
	$(window).resize(function() {
		var pegaPosicao = $(".bt-compartilhe").offset();
		$(".compartilhar").animate({"left":pegaPosicao.left - 415, "top":pegaPosicao.top}, velAnim, effectAnim);
	});
	
	// Input
	var input = document.getElementsByTagName("input");
	for (var a=input.length-1; a >= 0; a--) {
		if (input[a].type != "text") { continue; }
		input[a].mask = input[a].value;
		input[a].onfocus = function() {
			if (this.value == this.mask) { this.value = ""; }
		};
		input[a].onblur = function() {
			if (this.value == "") { this.value = this.mask; }
		};
	}
	
	// Mascaras formularios
	if (typeof $.fn.mask != "undefined") {
		$(".masc_telefone").mask("(99) 9999-9999");
		$(".masc_cpf").mask("999.999.999-99");
		$(".masc_data").mask("99/99/9999");
		$(".masc_hora").mask("99:99");
		$(".masc_cep").mask("99999-999");
	}
});

/**
  * Função validar favoritos
  * @param grande Imagem
  * @param maior Imagem
  * @param legenda Legenda
  * @return mensagem de erro
  **/
function galeria(grande, maior, legenda) {
	$("#a-grande").attr("href", maior);
	$("#a-grande").attr("title", legenda);
	$("#img-grande").attr("src", grande);
	$("#img-grande").attr("alt", legenda);
}

/**
  * Função limpa espaço
  * @param str String
  * @return nada
  **/
function getTrim(str) {
	if(typeof(str) !== "undefined"){
		return str.replace(/^\s+|\s+$/g, "");
	}else{
		return "";
	}
}

/**
  * Formata número
  * @param $campo int id
  * @param $event Evento
  * @return String
  **/
function formataNumero(campo, e) {
	t = typeof window.event != "undefined" ? window.event.keyCode : e.which;
	if((isNaN(String.fromCharCode(t)) || (t == 32)) && (t != 8 && t != 0)) {
		return false;
	}
}

/**
  * Função seleciona os checkbox
  * @param name Nome do input
  * @param checked Verifica se está selecionado
  * @return nada
  **/
function selecinaCampos(name,checked) {
	var elements = document.getElementsByTagName("input");
	for(i = 0; i < elements.length; i++) {
		if(elements[i].type == "checkbox" && elements[i].name.indexOf(name) != -1) {
			if (!checked) {
				elements[i].checked = "";
			} else {
				elements[i].checked = "checked";
			}
		}
	}
}

/**
  * Função que valida a data
  * @param String $value data
  * @return boolean
  **/
function validaData(campo) {
    var valor = campo.split("/");
    if(valor[0] != "" && valor[1] != "" && valor[2] != "") {
        data = new Date(valor[2], valor[1]-1, valor[0]);
        if (valor[2] != data.getFullYear() || valor[1] !=  data.getMonth()+1 || valor[0] != data.getDate() || valor[2] < 1902 || valor[2] > 2037) {
            return false;
        }
    }
    return true;
}

/**
  * Função que valida CPF
  * @param String $s CPF
  * @return boolean
  **/
function validaCpf(s) {
	if(s != "") {
		var cpf = s.replace(/\D/g,"");
		if (
			cpf == "00000000000" ||
			cpf == "11111111111" ||
			cpf == "22222222222" ||
			cpf == "33333333333" ||
			cpf == "44444444444" ||
			cpf == "55555555555" ||
			cpf == "66666666666" ||
			cpf == "77777777777" ||
			cpf == "88888888888" ||
			cpf == "99999999999" ||
			cpf.length != 11)
		{
			return false;
		}

		var soma = 0;
		for ( var i = 10 ; i > 1; i--) {
			soma += cpf.charAt(10 - i) * i;
		}
		d1 = (soma % 11 < 2) ? 0 : (11 - (soma % 11));
		if (d1 != cpf.charAt(9)) {
			return false;
		}
		soma = 0;
		for ($i=11 ; $i>1; $i--) {
			soma += cpf.charAt(11 - i) * i;
		}
		d2 = (soma % 11 < 2) ? 0 : (11 - (soma % 11) );
		if (d2 != cpf.charAt(10)) {
			return false;
		}
		return true;
	}
}

/**
  * Função chaca o valor do radio
  * @param String $radioObj
  * @return boolean
  **/
function getCheckedValue(radioObj) {
	if (!radioObj) {
		return "";
	}
	var radioLength = radioObj.length;
	if (radioLength == undefined) {
		if (radioObj.checked) {
			return radioObj.value;
		} else {
			return "";
		}
	}
	for (var i = 0; i < radioLength; i++) {
		if (radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

/**
  * Função Validar Formulário
  * @param form Identificador do form
  * @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");
		switch (relObj) {
			case "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;
				}
			break;
			case "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;
				}
			break;
			case "cpf":
				if ((!validaCpf(document.getElementById(form).elements[i].value)) || (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].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "data":
				if ((!validaData(document.getElementById(form).elements[i].value)) || (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].value = "";
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			case "radio":
			case "checkbox":
				if(getCheckedValue(document.getElementsByName(nomeObj))) {
				} else {
					alert(document.getElementById(form).elements[i].title);
					document.getElementById(form).elements[i].focus();
					return false;
				}
			break;
			default:
			break;
		}
    }
    return true;
}

/**
  * Função validar contato
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarContato(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-contato.php",
			data: str,
			success: function(txt) {
				if (getTrim(txt) == "0") {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				} else if (getTrim(txt) == "1") {
					alert("Mensagem enviada com sucesso.\nEstamos felizes em tê-lo como cliente. Obrigado pelo cadastro!");
					document.getElementById(form).reset();
				} else {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				}
			}
		});
	}
}

/**
  * Função validar reserva
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarReserva(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-reserva.php",
			data: str,
			success: function(txt) {
				if (getTrim(txt) == "0") {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				} else if (getTrim(txt) == "1") {
					alert("Mensagem enviada com sucesso.\nEstamos felizes em tê-lo como cliente. Obrigado pelo cadastro!");
					document.getElementById(form).reset();
				} else {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				}
			}
		});
	}
}

/**
  * Função validar currículo
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarCurriculo(form) {
	if (validaForm(form)) {		
		$(document).ready(function() {
            $("#" + form).ajaxForm(function(txt) {
				if (getTrim(txt) == "0") {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				} else if (getTrim(txt) == "1") {
					alert("Mensagem enviada com sucesso.\nEstamos felizes em tê-lo como cliente. Obrigado pelo cadastro!");
					document.getElementById(form).reset();
				} else {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				}
			});
        });
	}
}

/**
  * Função validar jantar presente
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarPresente(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-presente.php",
			data: str,
			success: function(txt) {
				if (getTrim(txt) == "0") {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				} else if (getTrim(txt) == "1") {
					alert("Mensagem enviada com sucesso.\nEstamos felizes em tê-lo como cliente. Obrigado pelo cadastro!");
					document.getElementById(form).reset();
				} else {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				}
			}
		});
	}
}

/**
  * Função validar convide
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarConvide(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-convide.php",
			data: str,
			success: function(txt) {
				if (getTrim(txt) == "0") {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				} else if (getTrim(txt) == "1") {
					alert("Mensagem enviada com sucesso.\nEstamos felizes em tê-lo como cliente. Obrigado pelo cadastro!");
					document.getElementById(form).reset();
				} else {
					alert("Não foi possível enviar a mensagem, tente novamente.");
				}
			}
		});
	}
}

/**
  * Função validar newsletter
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarNewsletter(form) {
	if (validaForm(form)) {		
		var str = $("#" + form).serialize();
		$.ajax({
			type: "POST",
			url: "lib/acao-form-newsletter.php",
			data: str,
			success: function(txt) {
				if (getTrim(txt) == "0") {
					alert("E-mail já cadastrado.");
				} else if (getTrim(txt) == "1") {
					alert("Estamos felizes em tê-lo como cliente. Obrigado pelo cadastro!");
					document.getElementById(form).reset();
					$.facebox.close();
				} else {
					alert("Não foi possível cadastrar o e-mail, tente novamente.");
				}
			}
		});
	}
}
