var banner_home_atual = 1;
var total_destaques = 0;
var tempo_parado_home = false;

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

function mudar_banner_home(numero_banner){
    $("#home-banner-" + banner_home_atual).fadeOut('slow', function(){
        $("#home-banner-" + numero_banner).fadeIn('slow', function(){
            $("#botao-home-banner-" + banner_home_atual).removeClass("ativo"); 
            $("#botao-home-banner-" + numero_banner).addClass("ativo"); 
            banner_home_atual = numero_banner;
            if (tempo_parado_home == true){
                iniciar_timer_destaques(); 
                tempo_parado_home = false; 
            }
        });
    });
    
    
}

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

