IncludeJavaScript("scripts/cufon.js"); // Núcleo do Cufón
IncludeJavaScript("scripts/jquery.cycle.js"); // Cycle
IncludeJavaScript("scripts/jquery.ui.totop.js"); // Cycle
IncludeJavaScript("scripts/jquery.flash.js"); // Flash
IncludeJavaScript("scripts/jquery.facebox.js"); // Facebox
IncludeJavaScript("scripts/jquery.scrollto.js"); // Smooth Scroll na tela
IncludeJavaScript("scripts/jquery.easing.js"); // Easing
IncludeJavaScript("scripts/jquery.maskedinput.js"); // Máscaras para formulários 
IncludeJavaScript("scripts/jquery.form.js"); // Forms
IncludeJavaScript("scripts/jquery.multifile.js"); // Multifile

// Funções
$(function() {

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

	// Quart
	$().UItoTop({ easingType: "easeOutQuart" });
	
	// Flash menu principal
	$(".menu-flash").flash({
	    src: "swf/menu.swf",
	    width: 960,
	    height: 158,
		wmode: "transparent",
		expressInstall: true
	});
	
	// Flash principal topo
	$(".flash-top").flash({
	    src: "swf/banner-top.swf",
	    width: 940,
	    height: 340,
		wmode: "transparent",
		expressInstall: true
	});
	
	// Balão de textos
	$(".balaoDesc, .balaoFazemos, .endereco, .redesSociais, .msg, .bgtwitter").hide();

	// Pessoa
	$(".pessoaIndividuo").click(function() {
		$(this).parent().find(".balaoDesc").slideDown();
		$(this).find(".plus").css("display","block");
		return false;
	});

	// Fechar balão
	$(".closeBaloon").click(function() {
		$(this).parent().slideUp();
		$(this).parent().parent().find(".plus").fadeOut();
		return false;
	});

	// Clientes
	$(".lista-cliente").click(function() {
		$(".aberto").slideUp().removeClass("aberto");
		if (!$(this).parent().find(".balaoFazemos").hasClass("aberto")) {
			$(this).parent().find(".balaoFazemos").addClass("aberto").slideDown();
		} else {
			$(".balaoFazemos").slideUp().removeClass("aberto");
		}
		return false;
	});

	// Projetos
	$("#listaFazemos").masonry({ columnWidth: 480 });

	// Cycle serviços
	$(".cycleFazemos").cycle({
		fx: "scrollHorz",
		prev: ".bt-esquerda",
		next: ".bt-direita",
		timeout: 0
	});
	
	$('.them').cycle({
		fx: 'fade', // tipo de efeito de transição
		speed: 'slow', // velocidade do efeito de transição
		timeout: 5000, // velocidade da transição de uma imagem a outro
		pager:  '.themNav', // elemento que contera a navegação da galeria
		pagerEvent: 'mouseover', // joga o mouseover na paginação
		pause: true,
		pagerAnchorBuilder: function(idx, slide) { 
			return '.themNav li:eq(' + idx + ') a'; // retorna a string seletora para ancoras ja existentes
		}
	});

	// Cycle projeto
	$(".cycleQuem").cycle({
		fx: "scrollHorz",
		prev: ".bt-1esquerda",
		next: ".bt-1direita",
		timeout: 0
	});

	// Abilitar descrição do projeto
	$(".cycleQuem ul li a").click(function() {
		var projeto = $(this).attr("href");		
		$(".listaCases").slideUp();
		$(projeto).slideDown();
		return false;
	});

	// Voltar para listagem de projetos
	$(".bt-voltar").click(function() {
		$(".listaCases").slideDown();
		$(".detalheCases").slideUp();
		return false;
	});

	// Controle
	var effectAnim = "easeOutBounce";
	var velAnim = "1000";
	var velShow = "3000";
	var velHide = "1000";

	// Rodapé
	$("#rodape").hover(function() {
		$(this).animate({ height: "259px" }, velAnim, effectAnim);
		setTimeout(function() {
			$(".endereco").fadeIn(velShow);
			$(".redesSociais").fadeIn(velShow);
			$(".msg").fadeIn(velShow);
			$(".bgtwitter").fadeIn(velShow);
		}, 500);
	}, function() {
		$(this).animate({ height: "95px" }, velAnim, effectAnim);
		setTimeout(function() {
			$(".endereco").fadeOut(velHide);
			$(".redesSociais").fadeOut(velHide);
			$(".msg").fadeOut(velHide);
			$(".bgtwitter").fadeOut(velHide);
		}, 200);
	});

	// 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 rolar a página conforme menu
  * @param link
  * @return nada
  **/
function rolaPage(link) {
	switch(link)
	{
	case "link1":
		$(window).scrollTo( "1000", 1000, { easing: "easeOutSine" });
		break;
	case "link2":
		$(window).scrollTo( "2150", 1000, { easing: "easeOutSine" });
		break;
	case "link3":
		$(window).scrollTo( "3200", 1000, { easing: "easeOutSine" });
		break;
	case "link4":
		$(window).scrollTo( "4200", 1000, { easing: "easeOutSine" });
		break;
	default:
		$(window).scrollTo( "0", 1000, { easing: "easeOutSine" });
	}	
}

/**
  * Função rolar a página para "o que foi feito" e abre projeto
  * @param link
  * @return nada
  **/
function rolaPageClick(id) {
	$(".listaCases").slideUp();
	$("#div-projeto-"+id).slideDown();
	$(window).scrollTo( "4200", 1000, { easing: "easeOutSine" });
}

/**
  * 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 monta caixa de seleção
  * @param div DIV
  * @param id Identificador
  * @return nada
  **/
function montaCaixa(div, id, padrao) {
	$.ajax({
		type: "POST",
		url: "lib/acao-monta-caixa.php",
		data: "div=" + div + "&id=" + id + "&padrao=" + padrao,
		success: function(txt) {
			$("#" + div).html(txt);
		}
	});
}

/**
  * 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 queremos você
  * @param form Identificador do form
  * @return mensagem de erro
  **/
function validarQueremosVoce(form) {
	if (validaForm(form)) {		
		$(document).ready(function() {
            $("#" + form).ajaxForm(function(txt) {
				if (getTrim(txt) == "1") {
					alert("Cadastro realizado com sucesso.");					
					document.getElementById(form).reset();
					$(".close_image").click();
					return false;
				}
				alert(txt);
            });
        });
	}
}

























