Carroussel = function(id, pieceWidth, animateDelay){
	this.carroussel = this;
    this.divElement = $("#" + id);
    this.current = 0;
    this.howMany = this.divElement.find(".piece").size();
    if(pieceWidth)
        this.pieceWidth = pieceWidth;
    else
        this.pieceWidth = 766;
        
    if(animateDelay)
        this.animateDelay = animateDelay;
    else
        this.animateDelay = 500;
    
    this.prev = function(numPieces){
        if(this.current <= 0)
            return;
            
        if(!numPieces || numPieces == 0)
            numPieces = 1;
        this.current -= numPieces;
        this.divElement.find(".wrapper").animate({
            marginLeft: "+=" + (this.pieceWidth * numPieces) + "px"
        },  this.animateDelay);   
        this.updateMenu();
    };
    
    this.next = function(numPieces){
        if(this.current >= this.howMany - 1)
            return;

        if(!numPieces || numPieces == 0)
            numPieces = 1;

        if(this.current + numPieces > this.howMany - 1)
            numPieces = this.howMany - this.current - 1;
        this.current += numPieces;            
        this.divElement.find(".wrapper").animate({
            marginLeft: "-=" + (this.pieceWidth *  numPieces) + "px"
        },  this.animateDelay);  
        this.updateMenu();        
    };
    
    this.connect = function(){
        this.divElement.find("a.prev")[0].carroussel = this;
        this.divElement.find("a.next")[0].carroussel = this;
        this.divElement.find("a.prev").click(function(){this.carroussel.prev(1); return false;});    
        this.divElement.find("a.next").click(function(){this.carroussel.next(1); return false;}); 
        this.updateMenu();
    };    
    
    this.updateMenu = function(){
        var menuItems = this.divElement.find(".carroussel_menu").find("li");
        menuItems.removeClass("active");
        for(var i = 0; i < menuItems.length; i++){
            if(i == this.current){
                $(menuItems.get(i)).addClass("active");
                break;
            }
        }
    }
	
	this.goTo = function(index){
        var diff = this.current - index;
        if(diff == 0)
            return;
        var forward = diff < 0;      
        diff = Math.abs(diff);
        if(forward)
            this.next(diff);
        else
            this.prev(diff);
	};
	
    this.connect();
    return true;

};

