var Slider = new Class({

    _moveBy: 630,
    _width: 0,
    _limit: 0,

    _fx: null,
    _wrap: null,
    _slide: null,
    _curPos: 0,

    initialize: function() {
        this._wrap = $('hwh_wrap');
        this._slide = $('hwh');
        this._fx = new Fx.Scroll(this._wrap, {wheelStops: false, offset: {x: -10, y: 0}});
        this._fx.toLeft();

        $('hwh_left').addEvent('click', this.moveLeft.bind(this));
        $('hwh_right').addEvent('click', this.moveRight.bind(this));

        this._findContent();
    },

    _findContent: function() {
        this._wrap.getElements('.hwh_thumb').each(function(thumb) {
            //if (this._curObj == null) this._curObj = thumb;

            this._width += thumb.getStyle('width').toInt()
                   + thumb.getStyle('padding-left').toInt()
                   + thumb.getStyle('padding-right').toInt()
                   + thumb.getStyle('margin-left').toInt()
                   + thumb.getStyle('margin-right').toInt();
        }.bind(this));
        
        this._wrap.getElements('.hwh_thumb_wide').each(function(thumb) {
            //if (this._curObj == null) this._curObj = thumb;

            this._width += thumb.getStyle('width').toInt()
                   + thumb.getStyle('padding-left').toInt()
                   + thumb.getStyle('padding-right').toInt()
                   + thumb.getStyle('margin-left').toInt()
                   + thumb.getStyle('margin-right').toInt();
        }.bind(this));
        
        this._width += 10;

        this._limit = this._width - this._wrap.getStyle('width').toInt();

        this._slide.setStyle('width', this._width + 'px');
    },

    moveLeft: function(by) {
        this._curPos = Math.max( 0, this._curPos - this._moveBy );
        this._fx.start(this._curPos, 0);
        //console.log(this._moveBy);
    },

    moveRight: function() {
        this._curPos = Math.min( this._curPos + this._moveBy, this._limit );
        this._fx.start(this._curPos, 0);
        //console.log(this._moveBy);
    }

});

window.addEvent('domready', function() {
    var _SLIDER = new Slider();
});