$(document).ready(function() {    
    $("#banner-home img").first().show();
    
    activeImage = 0;
    
    var reloadStart = function (){  
       if ($("#banner-home img").length > 1){
           showImage(activeImage + 1);
           
           timer = window.setTimeout(reloadStart, 7000);
       } else {
           window.clearInterval(timer);
       }
    }
    
    $(window).load(function(){
        timer = window.setTimeout(reloadStart, 5000);
    });
    
    function showImage(toShow){

       if (toShow > $("#banner-home img").length - 1){
           toShow = 0;
       }

       if (toShow < 0){
           toShow = $("#banner-home img").length - 1;
       }
           
       if (toShow != activeImage){
           $("#banner-home-numbers a").eq(activeImage).removeClass("active-number");

           $("#banner-home img").eq(toShow).fadeIn(2000, function(){
               $("#banner-home-numbers a").eq(toShow).addClass("active-number");
               activeImage = toShow
           });

           $("#banner-home img").eq(activeImage).fadeOut(2000, function(){});
       }  
    }
    
    
    $("#banner-home-numbers a").click(function(){
        window.clearInterval(timer);
        
        var toShow = $("#banner-home-numbers a").index(this);
        showImage(toShow);
        return false;
    });
    
    $("#banner-nav-left").click(function(){
        window.clearInterval(timer);

        showImage(activeImage - 1);
        return false;
    });
    
    $("#banner-nav-right").click(function(){
        window.clearInterval(timer);

        showImage(activeImage + 1);
        return false;
    });
});
