//-------------------- BEGIN -----------------------
/*
wrote by yf 2007.11.13
----------------------------------------------------

TAG's style:

	<div id="ScrollWindow" style="overflow:hidden;height:200px;width:600px;border:solid 1px black;" scrollamount="1" scrolldelay="1" scrollwidth="1000">
		data ......
	</div>

using method:

	var obj = new $$$ScrollWindow$$$(ScrollWindow);

----------------------------------------------------
*/

function $$$ScrollWindow$$$(scrollwindow){
	/*
	$$scrollwindow.scrollamount
	$$scrollwindow.scrolldelay
	$$scrollinit
	$$scrolltimer
	$$scrollcontent
	$$scrollwindow
	*/
	var $THIS						= this;

	this.$$scrollwindow				= scrollwindow;
	if((this.$$scrollwindow.scrollamount|0) < 1){this.$$scrollwindow.scrollamount = 1;}
	if((this.$$scrollwindow.scrolldelay |0) < 1){this.$$scrollwindow.scrolldelay  = 1;}
	if((this.$$scrollwindow.scrollwidth |0) < 1){this.$$scrollwindow.scrollwidth  = 300;}
	this.$$scrollinit				= false;
	this.$$scrolltimer				= 0; 
	this.$$scrollcontent			= null;	
	this.$$scrollwindow.onmouseover	= function(){$THIS.stop();}
	this.$$scrollwindow.onmouseout	= function(){$THIS.play();}

	this.play();
}

$$$ScrollWindow$$$.prototype._init = function(){
	
	var $ItemCount	= 0;
	var $I			= 0;
	var $Content	= '';
	
	$ItemCount = Math.ceil(this.$$scrollwindow.style.pixelWidth/this.$$scrollwindow.scrollwidth)+1;


	if(($ItemCount|0) > 10){
		$ItemCount = 10;
	}

	if(($ItemCount|0) < 2){
		$ItemCount = 2;
	}

	for($I = 0;$I < $ItemCount;$I++){
		$Content +=  '<DIV id="' + this.$$scrollwindow.id + 'Content" style="position: absolute;width:'+ 
					 this.$$scrollwindow.scrollwidth +'px;">' + 
					 this.$$scrollwindow.innerHTML + '</DIV>';
	}


	this.$$scrollwindow.innerHTML =$Content;
	this.$$scrollcontent = this.$$scrollwindow.all(this.$$scrollwindow.id +'Content');


	for($I = 0;$I < $ItemCount;$I++){
		this.$$scrollcontent[$I].style.pixelLeft = this.$$scrollcontent[$I].style.pixelWidth * $I;
	}


	this.$$scrollinit = true;
}


$$$ScrollWindow$$$.prototype._scroll = function(){
	var $I = 0;

	for($I=0;$I<this.$$scrollcontent.length;$I++){
		//to scroll to left
		if((this.$$scrollcontent[$I].style.pixelLeft + this.$$scrollcontent[$I].style.pixelWidth) <= 0){
			if($I==0){
				this.$$scrollcontent[0].style.pixelLeft  = this.$$scrollcontent[this.$$scrollcontent.length - 1].style.pixelLeft + 
														   this.$$scrollcontent[this.$$scrollcontent.length - 1].style.pixelWidth - 
														   this.$$scrollwindow.scrollamount;
			}else{
				this.$$scrollcontent[$I].style.pixelLeft = this.$$scrollcontent[$I - 1].style.pixelLeft + 
														   this.$$scrollcontent[$I - 1].style.pixelWidth ;
			}
			

		}else{
			this.$$scrollcontent[$I].style.pixelLeft     = this.$$scrollcontent[$I].style.pixelLeft - 
														   this.$$scrollwindow.scrollamount;
		} 
	}
}


$$$ScrollWindow$$$.prototype.stop = function(){
	if(this.$$scrolltimer>0){
		clearInterval(this.$$scrolltimer);
	}
}


$$$ScrollWindow$$$.prototype.play = function(){
	var $THIS = this;
	
	if(!this.$$scrollinit){
		this._init();
	}

	this.stop();
	this.$$scrolltimer = setInterval(function(){$THIS._scroll();},this.$$scrollwindow.scrolldelay);
}

//-------------------- END -----------------------




