var forforceSlider = 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,
            duration: 500,
            indication: false
        }, options || {});
        this.options.indication = false;
        this.slider = $(this.options.slider);
        var object = this;
        this.tween = new Fx.Tween(this.slider,{
            'duration':this.options.duration,
            onStart: function(){
                object.slider_active = true;
                if (this.left_number_indicator && this.options.indication){
                    this.left_number_indicator.set('html',object.left_number);
                }
            }.bind(this),
            onComplete: function() {
                object.slider_active = false;
                if (object.left_number <= 1) {
                    object.item_left.setStyles({
                        'opacity': 0.4,
                        'cursor' : 'default'
                    });
                } else {
                    object.item_left.setStyles({
                        'opacity': 1,
                        'cursor' : 'pointer'
                    });
                }

                if (object.left_number > ( object.block_count - object.items_visible)) {
                    object.item_right.setStyles({
                        'opacity': 0.4,
                        'cursor' : 'default'
                    });
                } else {
                    object.item_right.setStyles({
                        'opacity': 1,
                        'cursor' : 'pointer'
                    });
                }
            }
        });
        this.tween.start('left',0);
        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.block_count == 1) {
			$$(this.item_left, this.item_right).setStyle('display','none');
		} else {
            $$(this.item_left, this.item_right).setStyle('display','');
        }
        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.options.indication) {
            this.left_number_indicator = $(this.options.left_number_indicator);
            this.items_count_indicator = $(this.options.items_count_indicator);
			if (this.block_count == 1) {
				$$(this.left_number_indicator, this.items_count_indicator).setStyle('display','none');
			}
        }

        if (this.items_count_indicator && this.options.indication){
            this.items_count_indicator.set('html',this.block_count);
        }
    },

    reinitialize: function(){
        this.initialize(this.options);
    },

    scrollLeft: function(evt) {
        evt.stop();
        if (this.slider_active == true) {
            return false;
        }
        if (this.left_number <= 1) {
            return false;
        } else {
            this.left_number--;
            this.tween.start('left',(-1)*(this.left_number - 1)*this.options.block_width)
        }
    },

    scrollRight: function(evt) {
        evt.stop();
        if (this.slider_active == true) {
            return false;
        }if (this.left_number > ( this.block_count - this.items_visible) ) {
            return false;
        } else {
            this.left_number++;
            this.tween.start('left',(-1)*(this.left_number - 1)*this.options.block_width);
        }
    },

    scrollTo: function(num, instant){
        if (num < 1 || num > (this.block_count - this.items_visible + 1)) {
            return false
        } else {
            this.left_number = num.toInt();
            if (instant == true) {
                this.tween.set('left',(-1)*(this.left_number - 1)*this.options.block_width);
                this.tween.fireEvent('complete');
            } else {
                this.tween.start('left',(-1)*(this.left_number - 1)*this.options.block_width);
            }
        }
    }

});

