// JavaScript

function menuFeedBack(obj,pos) {
	$(obj).css("background-position",pos)
}

/** ********* CAMPOS FORMULÁRIO ********** */

function checarCampo(campo, valor) {
	if (campo.value == valor) {
		campo.value = '';
	}
}

function checarCampoVazio(campo, valor) {
	if (campo.value == '') {
		campo.value = valor;
	}
}

function fecharBanner()
{
	$('#bannerPopup').hide();
}

/** ************************************** */

jQuery(document).ready(function()
{	
	bannerPrincipal();
	
	if($('#tarjaDescricao').size())
	{
		$('#bgTarjaDescricao').css('height',($('#tarjaDescricao').height()+10)+'px');
	}

	if($('#foto').size())
	{
		$('#foto p').css('width',(615 - $('#foto img').width())+'px');
	}
	
	$('.linkHoverProjeto').mouseover(function(){
		$("p",this).css({"text-decoration":"underline"});      
		$("span.btDownload",this).css("background-position","0 -21px")
    }).mouseout(function(){
		$("p",this).css({"text-decoration":"none"});
		$("span.btDownload",this).css("background-position","0 0")
    });

	$('.linkHover').mouseover(function(){
		$("p",this).css({"text-decoration":"underline"});      
    }).mouseout(function(){
		$("p",this).css({"text-decoration":"none"});
    });

	
});

function bannerPrincipal(){
	if($('#bannerPrincipal').size()){
		var delay = 4;
		var time = 1.5;
		
		var itemAtual = parseInt($('#bannerPrincipal img:visible').attr("name"));
		var nextItem = (itemAtual < $('#bannerPrincipal img').size()-1) ? itemAtual+1 : 0;
		
		$('#bannerPrincipal img:visible').animate({opacity: 1.0}, delay*1000,function(){
			$("#bannerPrincipal img[name='"+nextItem+"']").css('z-index',1)
			.fadeIn(time*1000);
			
			$(this).css('z-index',0)
			.fadeOut(time*1000, function(){
				$("#bannerPrincipal a").removeClass('ativo');
				$("#bannerPrincipal a[name='"+nextItem+"']").addClass('ativo');
				bannerPrincipal();
			})																								 
		});
	}	
}

function bannerRollOver(id)
{
	var itemAtual = parseInt($('#bannerPrincipal img:visible').attr("name"));
	var nextItem = id;
	
	if(itemAtual != nextItem)
	{
		$("#bannerPrincipal img:animated").stop();		
		$("#bannerPrincipal img").css('display','none');
		$("#bannerPrincipal img[name='"+nextItem+"']").css('display','block');
		
		$("#bannerPrincipal a").removeClass('ativo');
		$("#bannerPrincipal a[name='"+nextItem+"']").addClass('ativo');
		
		bannerPrincipal();
	}
}

function cadastroNews() {
	if($("#cadNome").val() != "nome*" && $("#cadEmail").val() != "email*"){
		$("#msgCadastro").html("enviando...");
		$("#msgCadastro").load("ajaxCadastro.php?"+$("#cadastroIndex").serialize(), {}, function(responseText, textStatus, XMLHttpRequest){
			if(textStatus == "success"){
				if($("#statusCadastro").val() == "true"){
					$("#cadNome").val("nome*");
					$("#cadEmail").val("email*");
				}
			}
		});
	}else{
		$("#msgCadastro").html("preencha todos os campos!");
	}
}

/******************************************/

function indicacaoEnviar()
{
	if($("#seu_nome").val() && $("#seu_email").val() && $("#nome_amigo").val() && $("#email_amigo").val()){
		$("#MSG").css("color","#666666");
		$("#MSG").text("enviando...");
		
		$('#MSG').load("ajaxIndicar.php?"+$("#indique").serialize(), {}, function(responseText, textStatus, XMLHttpRequest){
			if(textStatus == "success"){
				if($("#statusIndicar").val() == 'true'){
					$("#seu_nome").val('');
					$("#seu_email").val('');
					$("#nome_amigo").val('');
					$("#email_amigo").val('');
					
					$("#MSG").css("color","#666666");
					$("#MSG").text("mensagem enviada!");
				}else{
					$("#MSG").css("color","#b10000");
					$("#MSG").text("falha ao enviar");
				}
			}else{
				$("#MSG").css("color","#b10000");
				$("#MSG").text("falha ao enviar");
			}
		});	
	}else{
		$("#MSG").css("color","#b10000");
		$("#MSG").text("preencha todos os campos");
	}
}

function carregarFoto(id)
{
	if(id)
	{
		$("#foto").load("ajaxFotos.php?id_foto="+id, {}, function(responseText, textStatus, XMLHttpRequest){
			if(textStatus != "success"){
				alert("erro interno no sevidor (código: 1002)");
			}
			else
			{
				$('#foto p').css('width',(615 - $('#foto img').width())+'px');				
			}
			
		});
	}
}

/******************************************/

function ajaxEnquete(){
	$("#alerta").load("ajaxVoto.php?"+$("#formEnquete").serialize(), {}, function(responseText, textStatus, XMLHttpRequest){
		if(textStatus != "success"){
			alert("erro interno no sevidor (código: 1002)");
		}
	});
}

/******************************************/

function contatoEnviar(){
	if($("#nome").val() && $("#email").val() && $("#assunto").val() && $("#mensagem").val()){
		$("#MSG").css("color","#333333");
		$("#MSG").html("enviando...");
		$("#MSG").load("ajaxContato.php?"+$("#formContato").serialize(), {}, function(responseText, textStatus, XMLHttpRequest){
			if(textStatus == "success"){
				if($("#statusContato").val() == "true"){
					$("#nome").val("");
					$("#email").val("");
					$("#telefone").val("");
					$("#cidade").val("");
					$("#assunto").val("");
					$("#mensagem").val("");
				}
			}
		});
	}else{
		$("#MSG").html("*preencha os campos obrigatórios!");
		$("#MSG").css("color","#B10000");
	}		
}

/******************************************/

function faleEnviar(){
	if($("#nome").val() && $("#email").val() && $("#cidade").val() && $("#estado").val() && $("#mensagem").val()){
		$("#MSG").css("color","#333333");
		$("#MSG").html("enviando...");
		$("#MSG").load("ajaxFale.php?"+$("#formFale").serialize(), {}, function(responseText, textStatus, XMLHttpRequest){
			if(textStatus == "success"){
				if($("#statusContato").val() == "true"){
					$("#nome").val("");
					$("#email").val("");
					$("#cidade").val("");
					$("#estado").val("");
					$("#mensagem").val("");
				}
			}
		});
	}else{
		$("#MSG").html("preencha todos os campos!");
		$("#MSG").css("color","#B10000"); // 1 campo $("#alert span").css ("color","#B10000");
	}		
}

/******************************************/

function mudarGaleria(id) {
	if(id){
		$("#tituloBannerGaleria span").html("carregando");
		$("#bannerGaleriaFotos").load("ajaxGaleria.php?reg_inicial="+id, {}, function(responseText, textStatus, XMLHttpRequest){
			if(textStatus == 'success')
			{
				if($('#tarjaDescricao').size())
				{
					$('#bgTarjaDescricao').css('height',($('#tarjaDescricao').height()+10)+'px');
				}
			}
		});
	}
}

/******************************************/

function ajaxEnquete(){
	$("#msgEnquete").load("ajaxVoto.php?"+$("#formEnquete").serialize(), {}, function(responseText, textStatus, XMLHttpRequest){
		if(textStatus != "success"){
			alert("erro interno no sevidor (código: 1002)");
		}
	});
}