var _slider = new slideShow();

function slideShow(){
    this.fields = '';
    this.current_element = 0;
    this.element_direction = 'left';
    this.transitions = new Array();
    this.transitions['left'] = 'Fx.Transitions.Sine.easeIn';
    this.transitions['right'] = 'Fx.Transitions.Sine.easeOut';
    this.element_margin = 0;
    this.element_animation = new Array();
    this.timeout = '';
    this.timer = 5000;

    this.setSlideShowInformation = function(el_id, el_margin, el_direction){
        this.element_selector = el_id;
        this.element_margin = el_margin;
        this.direction = el_direction;
        this.fields = $$('div.js-slideshow').length;
        this.setSlideShow();
    }
    
    this.setSlideShow = function(){
        var _element = $(this.element_selector);
        if (_element != null){
            this.element_animation['left'] = new Fx.Morph(_element,{
                'duration': '1000',
                'transition': eval(this.transitions['left'])
            });
            this.element_animation['right'] = new Fx.Morph(_element,{
                'duration': '1000',
                'transition': eval(this.transitions['right'])
            });
        }
    }

    this.startSlideShow = function(){
        setTimeout("_slider.setElement()", this.timer);
    }

    this.setElement = function(){
        if (this.element_animation['left'] != '' && this.element_animation['left'] != ''){
            _margin = this.element_margin;
            if (this.current_element < this.fields - 1){
                if (this.current_element > 0){
                    if (this.element_direction == 'left'){
                        ++this.current_element;
                    }
                    else{
                        --this.current_element;
                    }
                }
                else{
                    this.element_direction = 'left';
                    ++this.current_element;
                }
                _margin = this.current_element * _margin;
            }
            else{
                this.element_direction = 'right';
                --this.current_element;
                _margin = this.current_element * _margin;
            }
            this.element_animation[this.element_direction].start({
                'left': '-' + _margin + 'px'
            });
//            alert(this.element_direction + ' ' + this.current_element);
            this.timeout = setTimeout("_slider.setElement()", this.timer);
        }
    }
    
}
