var banner_home_atual = 1;
var total_destaques = 0;
var tempo_parado_home = false;
var clicado = false;
var url = "";


 $(document).ready(function(){
       $(".bt-voltar").bind("click", function(){
	    window.history.go(-1);
	    return false;
	});

	$("#container-patrocinios").cycle('fade');
	
	
	
	/*ADICIONADO SUBSTITUINDO A FN MUDA_BANNER*/
	$("#home-banners").cycle('fade');
	
	
	$("#imagem_congresso_verso").mousemove(function(e){
		var $imagem_grande = $("#imagem_congresso_verso_grande");
		$imagem_grande.parent().show();
		
		var y = e.pageY - $(this).offset().top;
		
		console.log(y);
		$imagem_grande.css({position:"relative", top:-y * 1.3})
	});
	
	$("#imagem_congresso_verso").mouseout(function(){
		$("#imagem_congresso_verso_grande").parent().hide();
	});

	$("#formulario-newsletter").ajaxForm({
		dataType: "json",
		success: function(responseText, responseStatus){
			if(responseText.status == "sucesso"){
				$("#alerta-newsletter").html("Email cadastrado com sucesso.");
			} else if(responseText.status == "error"){
			    $("#alerta-newsletter").html("Este email já esta cadastrado.");
			    
			}
			$("#alerta-newsletter").css("display", "block");
		}
	});

	$("#conheca-tambem-proximo").bind("click", function(evento){
		var viewport_conheca_tambem = 190;
		
		var movimento = $("#conheca-tambem-links").css("left");
		if (movimento == 'auto'){
		    movimento = 0; 
		}
		if (Math.abs(parseInt(movimento)) + viewport_conheca_tambem < $("#conheca-tambem-links > li").length * viewport_conheca_tambem ){
		    $("#conheca-tambem-links").animate({
			    left: (parseInt(movimento) - 190) + "px"
		    });
		}
		return false;
	});
	
	$("#conheca-tambem-anterior").bind("click", function(evento){
		var viewport_conheca_tambem = 190;
		evento.preventDefault();
		var movimento = $("#conheca-tambem-links").css("left");
		if (Math.abs(parseInt(movimento)) - viewport_conheca_tambem >= 0 ){
		    $("#conheca-tambem-links").animate({
			    left: (parseInt(movimento) + 190) + "px"
		    });
		}	
	});



	url = window.location.toString();

	if(url.indexOf('#2') != -1){
		banner_home_atual = 2;
	}else if(url.indexOf('#3') != -1){
		banner_home_atual = 3;
	}else if(url.indexOf('#4') != -1){
		banner_home_atual = 4;
	}

	mudar_banner_home(banner_home_atual);

	total_destaques =  $("#home-banners > li").length;
	$("#lista-home-destaques > li > a").bind("click", function(){
		$("#home-banners").stopTime('banners-home');
		tempo_parado_home = true
		if(!clicado) mudar_banner_home($(this).parent().attr("id").substr($(this).parent().attr("id").lastIndexOf("-") + 1));
		return false;
	})
	iniciar_timer_destaques();

	placeholder('facaPesquisa', 'Digite um termo');
	placeholder('informeEmail', 'Informe seu e-mail');


	$('#zoommais').bind('click',function(){
		var tam_letra = parseInt($('#container_noticia p:first span').css('font-size').split('px')[0]);
		tam_letra = tam_letra >= 18 ?18 :tam_letra+2;
		$('#container_noticia p:first span').css('font-size',tam_letra);
	});

	$('#zoommenos').bind('click',function(){
		var tam_letra = parseInt($('#container_noticia p:first span').css('font-size').split('px')[0]);
		tam_letra = tam_letra <= 12 ?12 :tam_letra-2;
		$('#container_noticia p:first span').css('font-size',tam_letra);
	});





});
 

function placeholder(id, value) {
	$('#' + id).bind('focus', function() {
		if($(this).val() === value) {
			$(this).val('');
		}
	});

	$('#' + id).bind('focusout', function() {
		if($.trim($(this).val()) === '') {
			$(this).val(value);
		}
	});
}

function mudar_banner_home(numero_banner){
/*	clicado = true;
	$("#home-banner-" + banner_home_atual).animate({position:"relative",left:100, top:100},'slow', function(){
		$("#botao-home-banner-" + banner_home_atual).removeClass("ativo"); 
		$("#botao-home-banner-" + numero_banner).addClass("ativo");
	});
	
	$("#home-banner-" + numero_banner).animate({position:"relative",left:0, top:0},'slow', function(){
			clicado = false;
			banner_home_atual = numero_banner;
			if (tempo_parado_home == true){
				iniciar_timer_destaques(); 
				tempo_parado_home = false; 
			}
	});
	
*/	
}



function iniciar_timer_destaques(){
	$("#home-banners").everyTime('3s', 'banners-home', function(){    
		if (banner_home_atual == total_destaques) {
			mudar_banner_home(1);  
		} else {
			mudar_banner_home(parseInt(banner_home_atual) + 1);
		}
	}); 
}

