Boutikcircus_Slideshow = Class.create({
    
    initialize: function(slideshow,height,nb,tempo) /* nb : nombre de produits à afficher dans le slide */
    {
        this.slideshow = $(slideshow);
        this.count = this.slideshow.getElementsByClassName('element-slideshow').length - nb + 1;
        this.height = height;
        this.position = 0;
        this.tempo = tempo;
        this.puceActiveName = 'puce_0';
        $(this.puceActiveName).addClassName('active');
        if (tempo != 0 && this.count>0) {
            this.autoAnime(this);
        }
    },
    
    animeRight: function()
    {
        if (this.tempo > 0)
            this.anim.stop();
        if (this.count > 0) {
        if (this.position == this.height*(this.count-1)) {
            new Effect.Move(this.slideshow, { y: this.height*(this.count-1), x: 0, duration: .4 });
            this.position = 0;
        } else {
            new Effect.Move(this.slideshow, { y: -this.height, x: 0, duration: 0.2 });
            this.position = this.position+this.height;
        }
        if (this.tempo > 0)
            this.autoAnime(this);
        }
    },
    
    animeLeft: function()
    {
        if (this.tempo > 0)
            this.anim.stop();
        if (this.count > 0) {
            if (this.position == 0) {
                new Effect.Move(this.slideshow, { y: -this.height*(this.count-1), x: 0, duration: .4 });
                this.position = this.height*(this.count-1);
            } else {
                new Effect.Move(this.slideshow, { y: this.height, x: 0, duration: 0.2 });
                this.position = this.position-this.height;
            }
            if (this.tempo > 0)
                this.autoAnime(this);
        }
    },
    
    autoAnime: function(data)
    {
        this.anim = new PeriodicalExecuter( function(pe) {
            if (data.position == data.height*(data.count-1)) {
                new Effect.Move(data.slideshow, { y: data.height*(data.count-1), x: 0, duration: .4 });
                data.position = 0;
            } else {
                new Effect.Move(data.slideshow, { y: -data.height, x: 0, duration: 0.2 });
                data.position = data.position+data.height;
            }
            $(data.puceActiveName).removeClassName('active');
            data.puceActiveName = 'puce_' + data.position/data.height;
            $(data.puceActiveName).addClassName('active');
        }, 5);
    },
    
    setPosition: function(data)
    {
        if (this.tempo > 0)
            this.anim.stop();
        if (this.count > 0) {
            new Effect.Move(this.slideshow, { y: this.position - data*this.height, x: 0, duration: 0.2 });
            this.position = data * this.height;
            $(this.puceActiveName).removeClassName('active');
            this.puceActiveName = 'puce_' + this.position/this.height;
            $(this.puceActiveName).addClassName('active');
            if (this.tempo > 0)
                this.autoAnime(this);
        }
    }
});
