 

function GoodsScroll(n1,n2) {
	this.Name = n1;
	this.GoodsName = n2;
	this.Speed = 85;
	this.GoodsSetTime = null;
	this.sState = "next";

	
	this.LiBox_Num = 1;										// ÇÑ¹ø¿¡ ½ºÅ©·ÑÇÒ »óÇ° °¹¼ö
	this.LiBox_HiddenNum = 2;								// ÇÑ¹ø¿¡ ³ëÃâÇÒ »óÇ° °¹¼ö
	
	this.GoodsSetting();									// ÃÊ±â°ª
	this.DivSize();											// ³ëÃâµÉ »óÇ°ÀÇ ³ÐÀÌ ³ôÀÌ°ª
	this.GoodlsArrange();									// »óÇ° ¼ø¼­´ë·Î Áø¿­ÇÏ±â
	
	this.doMove = function() {
		if(this.sState == "next") {
			this._nextFrame();
		} else if(this.sState == "prev") {
			this._prevFrame();
		}
	}
}

GoodsScroll.prototype.GoodsSetting = function() {
	this.GoodsBox = document.getElementById(this.GoodsName);
	this.OlBox = this.GoodsBox.getElementsByTagName("ol")[0];
	this.LiBox = this.OlBox.getElementsByTagName("li");
	this.LiBox_Length = this.LiBox.length;					// »óÇ°ÀÇ ÃÑ °¹¼ö

	this.LiBox_Width = parseInt(this.LiBox.item(0).width,0);	// »óÇ° ÇÑ°³ÀÇ ³ÐÀÌ

	this.LiBox_Left = new Array();							// °¢ »óÇ°ÀÇ À§Ä¡°ªÀ» ÀúÀåÇÏ´Â ¹è¿­
}

GoodsScroll.prototype.DivSize = function() {
	this.DivBox = this.LiBox.item(0).getElementsByTagName("div");
	this.DivBox_Height = 0;

	for ( var i=0; i < this.DivBox.length; i++ ) {
		this.DivBox_Height = this.DivBox_Height + parseInt(this.DivBox.item(i).height,0);
	}

	this.GoodsBox.style.height = this.DivBox_Height + 5 + "px";
	this.GoodsBox.style.width = this.LiBox_Width * this.LiBox_HiddenNum + "px";
}

GoodsScroll.prototype.GoodlsArrange = function() {
	this.Default_left = -(this.LiBox_Num * this.LiBox_Width);		// »óÇ°ÀÇ ÃÊ±â À§Ä¡°ª
	
	for ( var i=0; i < this.LiBox_Length; i++ ) {
		this.LiBox_Left[i] = this.Default_left + ( i * this.LiBox_Width );
		this.LiBox.item(i).style.left = this.LiBox_Left[i] + "px";
	}
	
	this.Last_Left = this.LiBox_Left[this.LiBox_Length-1];
}

GoodsScroll.prototype._nextFrame = function() {
	this.sState = "next";
	for ( var i=0; i<this.LiBox_Length; i++ ) {
		this.LiBox_Left[i] = this.LiBox_Left[i] - this.Speed;
		if ( this.LiBox_Left[i] == ( this.Default_left - this.LiBox_Width ) ) {
			this.LiBox_Left[i] = ( ( this.LiBox_Length - 1 ) * this.LiBox_Width ) + this.Default_left;
			this.LiBox[i].style.left = this.LiBox_Left[i] + "px"
		} else {
			this.LiBox[i].style.left = this.LiBox_Left[i]+"px";
		}
	}
	if ( this.LiBox_Left[0] % ( this.LiBox_Width * this.LiBox_Num ) == 0 ) {
		this.GoodsSetTime = setTimeout(this.Name + "._nextFrame()",3000);
	} else {
		this.GoodsSetTime = setTimeout(this.Name + "._nextFrame()",100);
	}
}

GoodsScroll.prototype._prevFrame = function() {
	this.sState = "prev";

	for ( var i=0; i<this.LiBox_Length; i++ ) {
		this.LiBox_Left[i] = this.LiBox_Left[i] + this.Speed;

		if ( this.LiBox_Left[i] == this.Last_Left + this.LiBox_Width ) {
			this.LiBox_Left[i] = this.Default_left;
			this.LiBox[i].style.left = this.LiBox_Left[i] + "px"
		} else {
			this.LiBox[i].style.left = this.LiBox_Left[i]+"px";
		}
	}
	if ( this.LiBox_Left[0] % ( this.LiBox_Width * this.LiBox_Num ) == 0 ) {
		this.GoodsSetTime = setTimeout(this.Name + "._prevFrame()",3000);
	} else {
		this.GoodsSetTime = setTimeout(this.Name + "._prevFrame()",100);
	}
}

GoodsScroll.prototype._nextBtn = function() {
	clearTimeout(this.GoodsSetTime);
	this.GoodsSetTime = setTimeout(this.Name + "._nextFrame()",100);
}
GoodsScroll.prototype._prevBtn = function() {
	clearTimeout(this.GoodsSetTime);
	this.GoodsSetTime = setTimeout(this.Name + "._prevFrame()",100);
}

GoodsScroll.prototype._stop = function() {
	clearTimeout(this.GoodsSetTime);
}
GoodsScroll.prototype._start = function() {
	if(this.sState == "next") {
			this.GoodsSetTime = setTimeout(this.Name + "._nextFrame()",100);
		} else if(this.sState == "prev") {
			this.GoodsSetTime = setTimeout(this.Name + "._prevFrame()",100);
		}
}

