$(document).ready(function(){
    Scroller.bind(".product-scroller");
});

var Class_Scroller = function(){
    this.c = null;
    this.ul = null
    this.i = null;
    
    this.width = 0;
    this.pos = 0;
    
    // thumb width
    this.tw = 132;
    // items visible in container
    this.itemsVisibile = 5;
};

Class_Scroller.prototype = {
    bind: function(selector)
    {
        var _this = this;
        _this.c = $(selector);
        
        if (_this.c.length == 0)
        {
            return false;
        }
        
        _this.ul = _this.c.find("ul");
        _this.i = _this.ul.find("li");
        _this.width = _this.i.length * _this.tw;
        
        _this.ul.css('width', _this.width + 'px');
        
        _this.c.find(".arrow-left").bind('click', function(){
            _this.prev();
            return false;
        });
        
        _this.c.find(".arrow-right").bind('click', function(){
            _this.next();
            return false;
        });
    },
    
    prev: function()
    {
        var _this = this;
        _this.pos += _this.tw;
        
        if (_this.pos >= 0)
        {
            _this.pos = 0;
        }
        
        _this.update();
    },
    
    next: function()
    {
        var _this = this;
        _this.pos -= _this.tw;
        
        var max = 0 - _this.width + (_this.tw * _this.itemsVisibile);
        if (_this.pos <= max)
        {
            _this.pos = max;
        }
        
        _this.update();
    },
    
    update: function()
    {
        var _this = this;
        _this.ul.animate({
            'marginLeft': this.pos + 'px'
            });
    }
};

var Scroller = new Class_Scroller();
