
var SellerScroll = function (options)
{
	this.SetOptions(options);
	this.lButton = this.options.lButton;
	this.rButton = this.options.rButton;
	this.oList = this.options.oList;
	this.showSum = this.options.showSum;

	this.iList = $(this.options.oList + "> dl");
	this.iListSum = this.iList.length;
	this.iListWidth = this.iList.outerWidth(true);
	this.moveWidth = this.iListWidth * this.showSum;
	this.dividers = Math.ceil(this.iListSum / this.showSum); //共分为多少块 
	this.moveMaxOffset = (this.dividers - 1) * this.moveWidth;
	$(this.options.oList).width(this.dividers * this.moveWidth);

	this.LeftScroll();
	this.RightScroll();
};
SellerScroll.prototype = {
	SetOptions: function (options)
	{
		this.options = {
			lButton: ".arrow",
			rButton: ".arrow1",
			oList: "#PicContainer",
			showSum: "1"//一次滚动多少个items 
		};
		$.extend(this.options, options || {});
	},
	ReturnLeft: function ()
	{
		return isNaN(parseInt($(this.oList).css("margin-left"))) ? 0 : parseInt($(this.oList).css("margin-left"));
	},

	LeftScroll: function ()
	{
		if (this.dividers == 1) return;
		var _this = this, currentOffset;
		$(this.lButton).click(function ()
		{
			currentOffset = _this.ReturnLeft();
			$(_this.oList).css("margin-left", -_this.moveWidth);
			for (var j = _this.iListSum - 1; j > (_this.iListSum - 1) - _this.showSum; j--)
			{
				$(_this.oList + ">dl:last").prependTo($(_this.oList));
			}

			$(_this.oList + ":not(:animated)").animate({ marginLeft: "+=" + _this.moveWidth }, { duration: "slow", complete: function ()
			{
				$(_this.oList).css("margin-left", "0px");
			}
			});
		});
	},
	RightScroll: function ()
	{

		if (this.dividers == 1) return;
		var _this = this, currentOffset;
		$(this.rButton).click(function ()
		{
			currentOffset = _this.ReturnLeft();
			$(_this.oList + ":not(:animated)").animate({ marginLeft: "-=" + _this.moveWidth }, { duration: "slow", complete: function ()
			{
				for (var j = 0; j < _this.showSum; j++)
				{
					$(_this.oList + ">dl:first").appendTo($(_this.oList));
				}
				$(_this.oList).css("margin-left", "0px");
			}
			});
		});
	}
};
/*
$(document).ready(function ()
{
	options = {
		lButton: ".arrow",//左边按钮
		rButton: ".arrow1",//右边按钮
		oList: "#PicContainer",//滚动区
		showSum: "1"//一次滚动多少个items 
	};
	var scroll = new SellerScroll(options);
}); 
*/
