var carrousel ={
nbSlide :0,
nbCurrent : 1,
elemCurrent : null,
elem : null,
timer : null,
leo : 0,

init : function(elem){
this.nbSlide = elem.find(".slide").length;
this.elem=elem;
elem.find(".slide").hide();
elem.find(".slide:first").show();
$(".slide-cadre").css('left','-338px');
elem.find(".slide-cadre:first").animate({left:'0'});
this.elemCurrent = elem.find(".slide:first");
carrousel.play();
elem.mouseover(carrousel.stop);
elem.mouseout(carrousel.play);

},
gotoSlide : function(num){
if(num==this.nbCurrent){return false;} 
var sens = -1;
var cssDeb = {"top" : sens*this.elem.height() };
var cssFin = {"top" : -sens*this.elem.height() };	
this.elem.find("#slide"+num).show().css(cssDeb);
this.elem.find("#slide"+num).animate({"top":0,"left":0},800,'linear');
this.elemCurrent.animate(cssFin,800,'linear');

if(num==1){leo=this.nbSlide}else{leo = num-1}
    $("#slide-titre"+leo).animate({left:'-338px'},400,'linear',function(){
        $("#slide-titre"+num).animate({left:'0'},400,'linear');
        });
couleur = $("#slide"+num).find('img').attr('class');
    //$('body').stop().animate({backgroundColor:couleur});
this.nbCurrent = num;
this.elemCurrent = this.elem.find("#slide"+num);
},

next : function(){
var num =this.nbCurrent+1;
if(num>this.nbSlide){
num = 1;
}
this.gotoSlide(num);
},
prev : function(){
var num =this.nbCurrent-1;
if(num < 1){
num = this.nbSlide;
}
this.gotoSlide(num);
},
stop : function(){
window.clearInterval(carrousel.timer);	
},
play : function(){
window.clearInterval(carrousel.timer);
carrousel.timer = window.setInterval("carrousel.next()",8000);
}
}
$(function(){	
carrousel.init($("#slider"));
$('pre.code').each(function(){
    $(this).text($(this).text());
    $(this).highlight();
});

});
