/**
 * Affiche un nombre de bloc et permet de scroller dessus
 *
 * @date mars 2010
 * @auteur Laurent Chaloupe
 */
var scrollBloc = new Class({
    Implements: Options,
    options: {
        maxBlocAff  : 3,                                              // nom de bloc max à afficher
        id: '',                                                       // id du bloc entier
        bloClass : '',                                                // nom de la class css des blocs
        idFlecheGauche: '',                                           // id de la fleche gauche
        idFlecheDroite: '',                                            // id de la fleche droite
        scrollLength:1		//nombre d'item à scroller 	
        },


    initialize : function( options ) {
        this.setOptions( options );

        if( !$( this.options.id ))
            alert( 'id TetiereScoreCenter est incorrect !' );

        this.match     = $$( '#' + this.options.id + ' ' + this.options.bloClass );
        this.total     = this.match.length;
        this.cursor    = 0;
        this.cursorMax = ( this.total - this.options.maxBlocAff );

        this.ev();
    },


    /**
     * Ajoute les évenements sur les fléches curseur
     */
    ev: function() {
        var thisObj = this;
        
        $( this.options.idFlecheGauche ).addEvent( 'click', function () {
        	thisObj.cursor -= (thisObj.options.scrollLength % thisObj.cursorMax == 0 ) ? thisObj.cursorMax :  thisObj.options.scrollLength % thisObj.cursorMax ;
        	//alert ('cursor -'+thisObj.cursor);
            thisObj.show();
        });

        $( this.options.idFlecheDroite ).addEvent( 'click', function () {
        	
            thisObj.cursor += (thisObj.options.scrollLength % thisObj.cursorMax == 0 ) ? thisObj.options.scrollLength : thisObj.options.scrollLength % thisObj.cursorMax  ;
            //alert ('cursor +'+thisObj.cursor);
            thisObj.show();
        });
    },


    /**
     * Cache tous les blocs
     */
    hidden: function() {
        this.match.each( function( item ) {
            item.setStyle( 'display', 'none' );
        });
    },


    /**
     * Affiche les blocs à partir du curseur
     */
    show: function() {
        this.hidden();

        if( this.cursor < 0 )
            this.cursor = this.cursorMax;

        if( this.cursor > this.cursorMax )
            this.cursor = 0;

        for( var i = this.cursor; i < this.cursor + this.options.maxBlocAff; i++ )
            this.match[ i ].setStyle( 'display', 'block' );
    }
});
