/*
* Lotus
*
*
*
*/

CaruselJs = new Class({

    Implements: [Options],

    options:
    {
        clasaThumb: 'link_poza',
        clasaThumbSelectat: 'link_poza_selectata',
        clasaCadruInfo: 'cadru_info',
        clasaContainerScroll: 'cnt_scroll',
//         clasaContainerScroll: 'lista_poze',
        clasaBtScrollStanga: 'scroll_stanga',
        clasaBtScrollDreapta: 'scroll_dreapta',
        clasaListaThumbs: 'lista_poze',
        scrollOffset: 571,
        offsetCurent: 0,
        pozaCurenta: 0,
        nrPozeTotale: 0,
        timpAfisare: 8000,
        scrollTransition: Fx.Transitions.Sine.easeInOut
    },

    initialize: function( options )
    {

        this.setOptions( options );

        this.options.nrPozeTotale = $$( '.' + this.options.clasaCadruInfo ).length;

        this.ajusteazaListaThumbs();

        this.infos = $( document.body ).getElements( '.' + this.options.clasaCadruInfo );
        this.leftScrollBt = $( document.body ).getElement( '.' + this.options.clasaBtScrollStanga );
        this.rightScrollBt = $( document.body ).getElement( '.' + this.options.clasaBtScrollDreapta );

        var thatCarusel = this;

        this.scroller = new Fx.Scroll( $( document.body ).getElement( '.' + this.options.clasaContainerScroll ), { 'duration' : 500, 'transition' :  this.options.scrollTransition } );
//         this.scrollerInstant = new Fx.Scroll( $( document.body ).getElement( '.' + this.options.clasaContainerScroll ), { 'duration' : 0, 'transition' :  this.options.scrollTransition } );

        this.leftScrollBt.addEvent( 'click', function( e ) {
            e.stop();
            thatCarusel.stopSlideshow();
            thatCarusel.scrollStanga();
            thatCarusel.listeaza = setTimeout( 'Carusel.initSlideshow()', thatCarusel.options.timpAfisare );
        } );

        this.rightScrollBt.addEvent( 'click', function( e ) {
            e.stop();
            thatCarusel.stopSlideshow();
            thatCarusel.scrollDreapta();
            thatCarusel.listeaza = setTimeout( 'Carusel.initSlideshow()', thatCarusel.options.timpAfisare );
        } );
    },

    initSlideshow: function() {
        this.scrollDreapta();
        this.listeaza = setTimeout( 'Carusel.initSlideshow()', this.options.timpAfisare );
    },

    stopSlideshow: function() {
        clearTimeout( this.listeaza );
    },

    scrollDreapta: function() {
        if ( this.options.pozaCurenta < this.options.nrPozeTotale - 1 ) {
            var scroller = new Fx.Scroll( $( document.body ).getElement( '.' + this.options.clasaContainerScroll ), { 'duration' : 500, 'transition' :  this.options.scrollTransition } );
            scroller.options.offset.x = this.options.scrollOffset;
            scroller.start();
            this.options.pozaCurenta++;
        }
        else {
            this.options.pozaCurenta = 0;
            this.options.offsetCurent = 0;
            var scroller = new Fx.Scroll( $( document.body ).getElement( '.' + this.options.clasaContainerScroll ), { 'duration' : 0, 'transition' :  this.options.scrollTransition } );
            var size = $( document.body ).getElement( '.' + this.options.clasaContainerScroll ).getScrollSize();
            scroller.options.offset.x = -size.x;
            scroller.start();
        }
    },

    scrollStanga: function() {
        if ( this.options.pozaCurenta > 0 ) {
            var scroller = new Fx.Scroll( $( document.body ).getElement( '.' + this.options.clasaContainerScroll ), { 'duration' : 500, 'transition' :  this.options.scrollTransition } );
            scroller.options.offset.x = -this.options.scrollOffset;
            scroller.start();
            this.options.pozaCurenta--;
        }
    },

    ajusteazaListaThumbs: function() {
        var nrElemente = $$( '.' + this.options.clasaCadruInfo ).length;
        var latimeElement = $( document.body ).getElement( ( '.' + this.options.clasaCadruInfo ) ).getStyle( 'width' ).toInt();
        $( document.body ).getElement( ( '.' + this.options.clasaListaThumbs ) ).setStyle( 'width', ( nrElemente * latimeElement ) );
    }

});