var Slider = new Class({

    Implements: [Options, Events],

    initialize : function(options) {
        this.options = $extend({
            slider: 'slider',
            item_left: 'slider-left',
            item_right: 'slider-right',
            block_width: 221,
            block_selector: '.gallery_item',
            number: 1,
            items_visible : 3
        }, options || {});

        this.slider = $(this.options.slider);
        this.tween = new Fx.Tween(this.slider);

        this.item_left  = $(this.options.item_left);
        this.item_right = $(this.options.item_right);
        var scrollLeftBound = this.scrollLeft.bindWithEvent(this);
        var scrollRightBound = this.scrollRight.bindWithEvent(this);
        this.item_left.addEvent('click',scrollLeftBound);
        this.item_right.addEvent('click',scrollRightBound);

        this.block_count = this.slider.getElements(this.options.block_selector).length;
        this.items_visible = this.options.items_visible;

        if (this.options.number > this.block_count || this.options.number < 2) {
            this.left_number = 1;
        } else {
            this.left_number = this.options.number;
            this.tween.set('left',(-1)*(this.left_number - 1)*this.options.block_width);
        }
        if (this.left_number > this.block_count - this.items_visible ) {
            this.item_right.removeClass('arrow_act');
            this.item_right.removeClass('active_arrows');
            this.item_right.removeClass('active_button');
            this.item_right.removeClass('slider_arrow_act');
            this.item_right.removeClass('a_act_arrow');
        }
    },

    scrollLeft: function(evt) {
        if (this.left_number <= 2) {
            this.item_left.removeClass('arrow_act');
            this.item_left.removeClass('active_arrows');
            this.item_left.removeClass('active_button');
            this.item_left.removeClass('slider_arrow_act');
            this.item_left.removeClass('a_act_arrow');
        }
        if (this.left_number <= 1) {
            this.item_left.removeClass('arrow_act');
            this.item_left.removeClass('active_arrows');
            this.item_left.removeClass('active_button');
            this.item_left.removeClass('slider_arrow_act');
            this.item_left.removeClass('a_act_arrow');
            return false;
        } else {
            this.item_right.addClass('arrow_act');
            this.item_right.addClass('active_arrows');
            this.item_right.addClass('active_button');
            this.item_right.addClass('slider_arrow_act');
            this.item_right.addClass('a_act_arrow');
            this.left_number--;
            this.tween.start('margin-left',(-1)*(this.left_number - 1)*this.options.block_width)
        }
    },

    scrollRight: function(evt) {
        if (this.left_number > this.block_count - this.items_visible-1 ) {
            this.item_right.removeClass('arrow_act');
            this.item_right.removeClass('active_arrows');
            this.item_right.removeClass('active_button');
            this.item_right.removeClass('slider_arrow_act');
            this.item_right.removeClass('a_act_arrow');
        }
        if (this.left_number > this.block_count - this.items_visible ) {
            return false;
        } else {
            this.item_left.addClass('slider_arrow_act');
            this.item_left.addClass('arrow_act');
            this.item_left.addClass('active_arrows');
            this.item_left.addClass('active_button');
            this.item_left.addClass('a_act_arrow');
            this.left_number++;
            this.tween.start('margin-left',(-1)*(this.left_number - 1)*this.options.block_width);
        }
    }

});
