function LoopScroll(Scroll_id,List_id,List_border,ScrollPix,ScrollTime,PausePix,PauseTime)
{
	this.ScrollPix=ScrollPix>0?ScrollPix:1;
	this.ScrollTime=ScrollTime>0?ScrollTime:1;
	this.PausePix=PausePix;
	this.PauseTime=PauseTime;
	this.ScrollCount=0;
	this.timer=null;


	this.Scroll_obj=$('#'+Scroll_id);
	this.List_obj=$('#'+List_id);

	this.ScrollTop=this.Scroll_obj.attr('scrollTop');

	this.Scroll_height=this.Scroll_obj.attr('offsetHeight');
	this.List_height=this.List_obj.attr('offsetHeight');

	if(this.Scroll_height < this.List_height)this.Scroll_height=this.List_height;
	if(this.List_height<=0)this.List_height=$('#'+List_border).attr('offsetHeight');

	/*init*/
	this.init();

	/*start scroll loop*/
	this.go();
}

LoopScroll.prototype.init=function()
{
	var obj=this;

	/*clone list*/
	var Lis=this.List_obj.find('li');
	var clone=null;
	for(var i=0;i<Lis.length;i++)
	{
		$(Lis[i]).clone().appendTo(this.List_obj);
	}

	/*event bind*/
	this.List_obj.bind('mouseover','',function(){obj.stop();});
	this.List_obj.bind('mouseout','',function(){obj.go();});
}

LoopScroll.prototype.Scroll=function()
{
	var obj=this,time=this.ScrollTime;

	if(this.PausePix > 0)
	{
		if(this.ScrollCount >= this.PausePix)
		{
			this.ScrollCount=0;
			time=this.PauseTime;
		}
		else
		{
			this.ScrollCount+=this.ScrollPix;
			this.step();
		}
	}
	else
	{
		this.step();
	}

	this.timer=window.setTimeout(function(){ obj.go(); },time);
}

LoopScroll.prototype.step=function()
{
	var ScrollTop=this.Scroll_obj.attr('scrollTop');

	if(ScrollTop >= this.List_height)
	{
		this.Scroll_obj.attr('scrollTop',this.ScrollTop+this.ScrollPix);
		this.ScrollCount=0+this.ScrollPix;
	}
	else
	{
		this.Scroll_obj.attr('scrollTop',ScrollTop+this.ScrollPix);
	}
}

LoopScroll.prototype.go=function()
{
	this.Scroll();
}

LoopScroll.prototype.stop=function()
{
	clearTimeout(this.timer);
}


/*****************************************/

function Scroll(Scroll_id,List_id,ScrollPix,ScrollTime,PausePix,PauseTime)
{
	this.Scroll_obj=$('#'+Scroll_id);
	this.List_obj=$('#'+List_id);

	this.Scroll_width=this.Scroll_obj.attr('offsetWidth');
	/*
	this.Scroll_left=this.Scroll_obj.attr('scrollLeft');
	*/

	this.ScrollPix=ScrollPix;
	this.ScrollTime=ScrollTime;
	this.PausePix=PausePix;
	this.PauseTime=PauseTime;
	this.ScrollCount=0;
	this.timer=null;
	this.step_count=0;
	this.Direction='right';
	this.WidthCount=0;
	this.List_unit_width=0;
	this.ScrollNew=0;
	this.margin_=0;

	this.init();
	this.bind_mouse();

}

Scroll.prototype.init=function()
{
	/*clone list*/
	var Lis=this.List_obj.find('li');
	var clone=null,count=0;

	this.margin_=parseInt($(Lis[0]).css('margin-left'))+parseInt($(Lis[0]).css('margin-right'));
	this.PausePix+=this.margin_;
	this.List_unit_width=($(Lis[0]).width()+this.margin_)*Lis.length;

	do
	{
		this.WidthCount++;
	}while(this.List_unit_width*this.WidthCount<this.Scroll_width);

	do
	{
		count++;
		for(var i=0;i<Lis.length;i++)
		{
			$(Lis[i]).clone().appendTo(this.List_obj);
		}
	}while( count <= this.WidthCount*3 );

	this.List_obj.width(this.List_unit_width*count);
	this.List_width=this.List_unit_width*count;

}

Scroll.prototype.bind_mouse=function()
{
	/*event bind*/
	var obj=this;
	this.List_obj.bind('mouseover','',function(){obj.stop();});
	this.List_obj.bind('mouseout','',function(){obj.go();});
}

Scroll.prototype.Scroll=function(Direction)
{
	var obj=this,time=this.ScrollTime;

	if(!Direction)
	{
		Direction=this.Direction;
	}
	else
	{
		this.Direction=Direction;
	}

	if(this.PausePix > 0)
	{
		if(this.ScrollCount >= this.PausePix ||  this.ScrollNew)
		{
			this.ScrollCount=0;
			time=this.PauseTime;
			this.ScrollNew=0;
		}
		else
		{
			this.ScrollCount+=this.ScrollPix;
			if(Direction=='right')
			{
				this.Right_scroll();
			}
			else
			{
				this.Left_scroll();
			}
		}
	}
	else
	{
		if(Direction=='right')
		{
			this.Right_scroll();
		}
		else
		{
			this.Left_scroll();
		}
	}

	this.timer=window.setTimeout(function(){ obj.go(Direction); },time);
}

Scroll.prototype.Left_scroll=function()
{

	var Scroll_left=this.Scroll_obj.attr('scrollLeft');

	if(Scroll_left >=  (this.List_width-(this.List_unit_width*this.WidthCount)))
	{
		this.Scroll_obj.attr('scrollLeft',this.List_unit_width);
		this.ScrollCount=0;
		this.ScrollNew=1;
	}
	else
	{
		this.Scroll_obj.attr('scrollLeft',Scroll_left+this.ScrollPix);
	}

}

Scroll.prototype.Right_scroll=function()
{

	var Scroll_left=this.Scroll_obj.attr('scrollLeft');

	if(Scroll_left <= this.List_unit_width)
	{
		this.Scroll_obj.attr('scrollLeft',this.List_width-(this.List_unit_width*this.WidthCount));
		this.ScrollCount=0;
		this.ScrollNew=1;
	}
	else
	{
		this.Scroll_obj.attr('scrollLeft',Scroll_left-this.ScrollPix);
	}

}

Scroll.prototype.go=function(Direction)
{
	this.Scroll(Direction);
}

Scroll.prototype.stop=function()
{
	clearTimeout(this.timer);
	this.timer=null;
}

Scroll.prototype.step=function(Direction)
{
	var obj=this,time=this.ScrollTime;
	var Scroll_left=this.Scroll_obj.attr('scrollLeft');

	if(this.PausePix > 0)
	{
		if(this.step_count >= this.PausePix)
		{
			this.step_count=0;
		}
		else
		{
			this.step_count+=this.ScrollPix;

			if(Direction=='right')
			{
				if(Scroll_left <= this.List_unit_width)
				{
					this.Scroll_obj.attr('scrollLeft',this.List_width-(this.List_unit_width*this.WidthCount));
					this.step_count-=this.ScrollPix;
				}
				else
				{
					this.Scroll_obj.attr('scrollLeft',Scroll_left-this.ScrollPix);
				}
			}
			else
			{
				if(Scroll_left >=  (this.List_width-(this.List_unit_width*this.WidthCount)))
				{
					this.Scroll_obj.attr('scrollLeft',this.List_unit_width);
					this.step_count-=this.ScrollPix;
				}
				else
				{
					this.Scroll_obj.attr('scrollLeft',Scroll_left+this.ScrollPix);
				}
			}

			window.setTimeout(function(){ obj.step(Direction); },time);
		}
	}

}
