jQuery(function($){
			
	//Mascara
	$("#tiDDD").mask("99");
	$("#tiTelefone").mask("9999-9999");
	
	//Fotos
	$('.exibeLightbox').lightBox();
	
	// Enviar contato via ajax
	$("#btEnviarContato").click(function(){
            
			$("#message").html("");
			$("#enviandomsg").show();
			
			var Nome      = $("#tiNome").val();
			var Email     = $("#tiEmail").val();
			var Empresa   = $("#tiEmpresa").val();
			var Cidade    = $("#tiCidade").val();
			var Estado    = $("#seEstado").val();
			var DDD       = $("#tiDDD").val();
			var Telefone  = $("#tiTelefone").val();
			var Mensagem  = $("#taMensagem").val();

            $.post(
                "json/contato_envia.php",
                { tiNome: Nome, tiEmail: Email, tiEmpresa: Empresa, tiCidade: Cidade, seEstado: Estado, tiDDD: DDD, tiTelefone: Telefone, taMensagem: Mensagem},
                function(data){
					
					$("#enviandomsg").hide();
                    $("#message").html(data.message);

                },
                "json"
            );
        });
	
	//Over em Botőes
	$("#btClinica").hover( function() { $(this).attr("src","img/clinica_rodape-over.jpg"); } ,	function() { $(this).attr("src","img/clinica_rodape.jpg"); });
	$("#btNewsletter").hover(  function() { $(this).attr("src","img/btok-over.png"); } , function() { $(this).attr("src","img/btok.png"); });	

	$.easing.backout = function(x, t, b, c, d){
		var s=0;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	};

});


function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}


function validaNewsletter()
{ 
	var erro = '';
	var email = document.getElementById('tiEmailNewsletter'); 
	var nome = document.getElementById('tiNomeNewsletter'); 
	
	if(!nome.value) { erro = erro + '- Nome\n'; }
	if(!email.value) { erro = erro + '- E-mail\n'; }
	
	if(erro) {
		alert('Preencha os campos\n'+erro);
		return false;
	}
	
	//E-mail
	if(!validaemail(email.value)) {
		alert('E-mail inválido.');
		return false;
	}
	
	return true;
}

function validaemail(email)
{
	p=email.indexOf("@");
	z=email.indexOf(".");
	if ((p<1 || p==(email.length-1)) || (z<1 || z==(email.length-1))) 
		return false;
	return true;
}

function abrirUrl(URL){
	window.open('http://'+URL)
}

function textCounter(campo, countcampo, maxlimit) {
	if (campo.value.length > maxlimit) 
		campo.value = campo.value.substring(0, maxlimit); 
	else
		countcampo.value = maxlimit - campo.value.length; 
}

function external(path) { // pass in the correct path to the function so we only need one <A> for infinite amount of calls from  flash                          
// if the lightbox does not exist we will make it                       
	if ($('a#lightbox').length == 0) {                             
		$("body").append("</A><A id='lightbox' style='visibility: hidden; position: absolute; left: -9999px;' href='http://www.thetruetribe.com/+path+'>calling js lightbox from flash</A>");                            
		$('a#lightbox').lightBox();                   
		// if it already exists but the path is different we will set the new path                      
	} else if ($('a#lightbox').attr("href") != path) {                             
		$('a#lightbox').attr("href", path);                   
	}      
	// now we will simulate the click here.                         
	$('a#lightbox').trigger("click");      
}


function fechar_popup(){
    $("#popup").hide();
};


