var SellerScroll = function (leftButton, rightButton, objList, playNum) {
    this.lButton = leftButton;
    this.rButton = rightButton;
    this.oList = objList;
    this.showSum = playNum;
    this.index = 0;

    this.iList = $("#" + this.oList + " > li");
    this.iListSum = this.iList.length;
    this.iListWidth = this.iList.width();
    this.moveWidth = this.iListWidth * this.showSum;

    this.dividers = Math.ceil(this.iListSum / this.showSum);
    this.moveMaxOffset = (this.dividers - 1) * this.moveWidth;
    this.LeftScroll();
    this.RightScroll();
};
SellerScroll.prototype = {
    ReturnLeft: function () {
        return isNaN(parseInt($("#" + this.oList).css("left"))) ? 0 : parseInt($("#" + this.oList).css("left"));
    },
    LeftScroll: function () {
        if (this.dividers == 1) return;
        var _this = this, currentOffset;
        $("#" + this.lButton).click(function () {
            if (_this.index <= 0) {
                return false;
            }
            _this.index = _this.index - 1;
            currentOffset = _this.ReturnLeft();
            if (currentOffset == 0) {
                for (var i = 1; i <= _this.showSum; i++) {
                    $(_this.iList[_this.iListSum - i]).prependTo($("#" + _this.oList));
                }
                $("#" + _this.oList).css({ left: -_this.moveWidth });
                $("#" + _this.oList + ":not(:animated)").animate({ left: "+=" + _this.moveWidth }, { duration: "slow", complete: function () {
                    for (var j = _this.showSum + 1; j <= _this.iListSum; j++) {
                        $(_this.iList[_this.iListSum - j]).prependTo($("#" + _this.oList));
                    }
                    $("#" + _this.oList).css({ left: -_this.moveWidth * (_this.dividers - 1) });
                }
                });
            } else {
                $("#" + _this.oList + ":not(:animated)").animate({ left: "+=" + _this.moveWidth }, "slow");
            }
        });
    },
    RightScroll: function () {
        if (this.dividers == 1) return;
        var _this = this, currentOffset;
        $("#" + this.rButton).click(function () {
            if ((_this.index + 5) >= _this.iListSum) {
                return false;
            }
            _this.index = _this.index + 1;
            currentOffset = _this.ReturnLeft();
            if (Math.abs(currentOffset) >= _this.moveMaxOffset) {
                for (var i = 0; i < _this.showSum; i++) {
                    $(_this.iList[i]).appendTo($("#" + _this.oList));
                }
                $("#" + _this.oList).css({ left: -_this.moveWidth * (_this.dividers - 2) });

                $("#" + _this.oList + ":not(:animated)").animate({ left: "-=" + _this.moveWidth }, { duration: "slow", complete: function () {
                    for (var j = _this.showSum; j < _this.iListSum; j++) {
                        $(_this.iList[j]).appendTo($("#" + _this.oList));
                    }
                    $("#" + _this.oList).css({ left: 0 });
                }
                });
            } else {
                $("#" + _this.oList + ":not(:animated)").animate({ left: "-=" + _this.moveWidth }, "slow");
            }
        });
    }
};
