var projeto_home_atual = 1;
var total_projetos = 0;
var tempo_parado_campanhas = false

$(document).ready(function(){
    total_projetos =  $("#home-projetos > li").length;
    $("#lista-home-projetos > li > a").bind("click", function(){
        $("#home-projetos").stopTime('home-projetos');
        tempo_parado_campanhas = true;
        mudar_projeto_home($(this).attr("id").substr($(this).attr("id").lastIndexOf("-") + 1));
        return false;
    })
    iniciar_timer_campanhas(); 
});   

function mudar_projeto_home(numero_projeto){
    $("#home-projeto-" + projeto_home_atual).fadeOut('slow', function(){
        $("#home-projeto-" + numero_projeto).fadeIn('slow', function(){
            $("#botao-home-projeto-" + projeto_home_atual).removeClass("ativo"); 
            $("#botao-home-projeto-" + numero_projeto).addClass("ativo"); 
            projeto_home_atual = numero_projeto;
            if (tempo_parado_campanhas == true){
                iniciar_timer_campanhas();
            }
        });
    }); 
}

function iniciar_timer_campanhas(){
    $("#home-projetos").everyTime('5s', 'home-projetos', function(){ 
        if (projeto_home_atual == total_projetos) {
            mudar_projeto_home(1);  
        } else {
            mudar_projeto_home(parseInt(projeto_home_atual) + 1);
        }
    }); 
}


