var carro = {

          nbSlide : 0,
		  nbCurrent :0,
		  elemCurrent : null,
		  elem : null,
		  timer : null,
		  
		  		 init : function(elem){
		 this.nbSlide = elem.find("img").length;
		 $("#cont_vis").css({"width":900*this.nbSlide});
		 //Création de la pagination	 si on a plus qu'un élément à afficher
		 if(this.nbSlide > 1){
		 elem.append("<div id='nav_min'></div>");
		 for(var i=0;i<=this.nbSlide-1;i++){
		 elem.find("#nav_min").append("<a href='#"+i+"' title=''><img src='images/img/"+i+"-min.jpg' /></a>");
		    }
		 }
		 
		 //initialisation du carrousel
		 this.elem = elem ;
		 this.elemCurrent = elem.find("#nav_min a:eq(0)");
         this.elemCurrent.addClass("current_min_vis");
		 this.timer = window.setTimeout( function(){"carro.auto_play()",5000 });
		 elem.find("#bandeau_noir").css({ opacity: 0.5 });
		 elem.find("#nav_min a").click(function(){ carro.gotoSlide($(this).attr("href")) });	

		 //On cré le timer
		 carro.play();
		 
		 //Stop quand on passe dessus
		 this.elem.mouseover(carro.stop);
		 this.elem.mouseout(carro.play);
	 
		},
		
		
		 gotoSlide : function(num){
		var getURl = num;
        var to_page=getURl.substring(getURl.lastIndexOf("#"));
		to_page = to_page.replace(/[^0-9]+/g,'');
		this.nbCurrent = to_page;
		this.elem.find("#nav_min a").removeClass("current_min_vis");
		this.elem.find("#nav_min a:eq("+to_page+")").addClass("current_min_vis");
        this.elem.find("#cont_vis").stop().animate({"left": -900*to_page } ,1000,'easeInOutExpo');
        return false;
		 },
		 
		 stop : function(){
		window.clearInterval(carro.timer);
		},
		
		play : function(){
		window.clearInterval(carro.timer);
		carro.timer = window.setInterval("carro.auto_play()",5000);
		},  
		
			auto_play : function(){
			
			//alert(this.nbCurrent)
            if(this.nbCurrent <= this.nbSlide){
			  if(this.nbCurrent == this.nbSlide){
			       this.nbCurrent = 0;
			    }
			this.elem.find("#cont_vis").stop().animate({"left": -900* this.nbCurrent } ,1000,'easeInOutExpo');
			this.elem.find("#nav_min a").removeClass("current_min_vis");
			this.elem.find("#nav_min a:eq("+this.nbCurrent+")").addClass("current_min_vis");
			}
			this.nbCurrent++
		}
		
		

}

$(function(){
carro.init($("#main_anim"));
});
    $(document).ready(function() {
		$(".bg_residentiel_box .img_in_residentiel_box").mouseenter(function(){$(".menu_2gamme").stop().slideUp(500);
		$(this).next(".menu_2gamme").stop().css("height","auto").slideDown('slow');})
        $(".bg_residentiel_box").mouseleave(function(){
		$(this).find(".menu_2gamme").stop().slideUp(500);
		})
    });

	  




