var carrousel = {
    
    slide : 0,
    elem : null,
    timer : null,
    courant : null,
    
    init : function(elem){
        if(elem.find(".visus img").length<=1){
            return false;
        }
		this.slide =  0;
        if(this.timer!=null){ window.clearInterval(carrousel.timer); }
        this.elem = elem;
		elem.find(".visus .title").hide();
        elem.find(".visus img").hide();
        elem.find(".visus .navigation li:first").addClass("active");
		elem.find(".visus .title:first").show();
        elem.find(".visus img:first").show();
        this.courant = elem.find(".visus img:first");
        this.timer = window.setInterval("carrousel.next()",4000);
        this.elem.find(".visus .navigation li").click(function(){
            window.clearInterval(carrousel.timer);
            carrousel.show(carrousel.elem.find(".visus .navigation li").index(this));
            carrousel.slide = carrousel.elem.find(".visus .navigation li").index(this);
            carrousel.timer = window.setInterval("carrousel.next()",4000);
 
        });
    },
    
    next : function(){
        this.slide++;
        if(this.slide>this.elem.find(".visus img").length-1){
            this.slide = 0;
        }
        this.show(this.slide);
    },
    
    prev : function(){
        this.slide--;
        if(this.slide<0){
            this.slide = this.elem.find(".visus img").length-1;
        }
        this.show(this.slide);
    },
    
    show : function(num){
		var titleHeight = this.elem.find(".visus .title").height();
		this.elem.find(".visus .title").animate({"bottom": -titleHeight},500);	
        this.elem.find(".visus img").css("z-index",1).hide();
        this.elem.find(".visus .navigation li.active").removeClass("active");
        this.courant.show();
        this.elem.find(".visus .navigation li:eq("+num+")").addClass("active");
		this.elem.find(".visus .title:eq("+num+")").css("bottom",-titleHeight).animate({"bottom": 0},500).show();
        this.elem.find(".visus img:eq("+num+")").css("z-index",2).fadeIn(1000);
        this.courant = this.elem.find(".visus img:eq("+num+")");
    }
};

jQuery(document).ready(function() {
    carrousel.init($('#carrousel'));
    $('.home #content .item').each(function(){
        $(this).find('.summary p:eq(0)').css('display','block');
    })
});
