
	/*
		作者：suoduan  
		创建日期：2008-03-21
		Scroller类功能，使指定id的div内容连续滚动
		
	*/
	function Scroller(sDivID,iScrollHeight,iTime,sDirection)
	{
		this.divID = sDivID; ////要滚动的div的id
		this.scrollHeight = iScrollHeight; //要滚动的div的高或宽
		this.time = iTime; ///滚动的速度
		this.direction = sDirection; ///滚动的方向 ,"up"向上 ,"left"向左
		this.preTop=0; //这个变量用于判断滚动条是否已经到了尽头
		this.objDiv=null;
		this.objTempDiv = null;
		this.templayerHeight =0;
		this.startScroll=startScroll;
		this.callback = callback;
		
		//this.stopscroll = false;
	}
	
	function startScroll()
	{
		this.objDiv = document.getElementById(this.divID);
		tempDiv = this.divID +"suo"
		this.objDiv.noWrap=true; ///内容不自动换行
		if (this.direction == "up")
		{
			this.objDiv.style.height = this.scrollHeight; ///设置div的高
			this.objDiv.style.overflowY="hidden";
		}else if (this.direction =="left")
		{
			this.objDiv.style.width = this.scrollHeight; ///设置div的宽
			this.objDiv.style.overflowX="hidden";
		}
		
		this.objDiv.name = '1';
		this.objDiv.onmouseover=new Function("this.name='0'"); //鼠标经过，停止滚动
		this.objDiv.onmouseout=new Function("this.name='1'"); //鼠标离开，开始滚动
		//这时候，内容区的高度是无法读取了。下面输出一个不可见的层"templayer"，稍后将内容复制到里面：
		document.write('<div id="' + tempDiv + '" style="position:absolute;z-index:100;visibility:hidden"></div>')
		this.objTempDiv = document.getElementById(tempDiv);
		//多次复制原内容到"templayer"，直到"templayer"的高度大于内容区高度：
		if (this.direction == "up")
		{
			while(this.objTempDiv.offsetHeight<this.scrollHeight){
				this.objTempDiv.innerHTML+=this.objDiv.innerHTML;
			} //把"templayer"的内容的“两倍”复制回原内容区：
			this.templayerHeight = this.objTempDiv.offsetHeight
		} else if (this.direction =="left")
		{
			var tempinner="";
			this.objTempDiv.innerHTML=this.objDiv.innerHTML;
			for (i = 1 ;i<=this.scrollHeight/this.objTempDiv.offsetWidth +1;i++)
			{
				tempinner = tempinner + "<td>" + this.objDiv.innerHTML + "</td>";
			}
			this.objTempDiv.innerHTML = "<table border='0' cellpadding='0' cellspacing='0'><tr>" +tempinner + "</tr></table>";
			//alert(this.objTempDiv.innerHTML);
			this.templayerHeight = this.objTempDiv.offsetWidth
		}
		this.objTempDiv.noWrap=true; //这句表内容区不自动换行
		this.objTempDiv.style.width=0; //于是我们可以将它的宽度设为0，因为它会被撑大
		this.objTempDiv.style.height=0;
		this.objTempDiv.style.overflowY="hidden"; //滚动条不可见
		this.objTempDiv.style.overflowX="hidden";
		if (this.direction == "up")
		{
			this.objDiv.innerHTML=this.objTempDiv.innerHTML+this.objTempDiv.innerHTML;
		}else if (this.direction =="left")
		{
			this.objDiv.innerHTML="<table border='0' cellpadding='0' cellspacing='0'><tr><td>" +this.objTempDiv.innerHTML+"</td><td>"+this.objTempDiv.innerHTML+"</td></tr></table>";
			//alert(this.objDiv.innerHTML);
		}
		var _this = this;
		var callback = function(){ _this.callback(); };
		window.setInterval(callback,_this.time);
		//setInterval("scrollUp()",this.time);
	}
	 function callback()
	 {
		 //alert("suo");
		if(this.objDiv.name=='0') return; //如果变量"stopscroll"为真，则停止滚动 
		if (this.direction == "up")
		{
			this.preTop=this.objDiv.scrollTop; //记录滚动前的滚动条位置
			this.objDiv.scrollTop+=1; //滚动条向下移动一个像素
			//如果滚动条不动了，则向上滚动到和当前画面一样的位置
			//当然不仅如此，同样还要向下滚动一个像素(+1)：
			if(this.preTop==this.objDiv.scrollTop){
				this.objDiv.scrollTop=this.templayerHeight-this.scrollHeight+1;
			}
		}else if (this.direction =="left")
		{
			this.preTop=this.objDiv.scrollLeft; //记录滚动前的滚动条位置
			this.objDiv.scrollLeft+=1; //滚动条向左移动一个像素
			//如果滚动条不动了，则向上滚动到和当前画面一样的位置
			//当然不仅如此，同样还要向下滚动一个像素(+1)：
			if(this.preTop==this.objDiv.scrollLeft){
				this.objDiv.scrollLeft=this.templayerHeight-this.scrollHeight+1;
			}
		}
	 }

