function AutoScroll(elementId, span)
{
	this.ctrlDiv = document.getElementById( elementId );
	this.span = span;
	this.pause = 45;
	this.stop = false;
	this.ctrlDiv.scrollTop = 0;
	
	this.items = new Array();
	
	var allitems = this.ctrlDiv.getElementsByTagName( "DIV" );
	
	for( var j = 0; j < allitems.length; j ++ ) {
		this.items[ this.items.length ] = allitems[ j ];
	}
	
	this.leadItem = 1;
	
	AutoScroll.instances[ elementId ] = this;
	
	var onTick = function() { AutoScroll.instances[ elementId ].scrollTick(); };
	var onMouseOver = function() { AutoScroll.instances[ elementId ].mouseOver(); };
	var onMouseOut = function() { AutoScroll.instances[ elementId ].mouseOut(); };
	
	setInterval( onTick, 50 );
	setEventHandler( this.ctrlDiv, "mouseover", onMouseOver );
	setEventHandler( this.ctrlDiv, "mouseout", onMouseOut );
}

AutoScroll.instances = new Array();

AutoScroll.prototype.scrollTick = function()
{
	if( this.stop ) return;
	
	if( this.pause <= 0 ) {
		if( ++this.ctrlDiv.scrollTop == this.span ) {
			while( this.ctrlDiv.childNodes[ 0 ] ) {
				this.ctrlDiv.removeChild( this.ctrlDiv.childNodes[ 0 ] );
			}
			
			var t = this.items.length;
			var next = this.leadItem;
			
			while( t-- ) {
				this.ctrlDiv.insertBefore( this.items[ next ], null );
				if( ++next >= this.items.length )
					next = 0;
			}
			
			if( ++ this.leadItem >= this.items.length )
				this.leadItem = 0;
			
			this.ctrlDiv.scrollTop = 0;
			this.pause = 40;
		}
	} else
		this.pause --;
}

AutoScroll.prototype.mouseOver = function()
{
	if( !this.stop ) {
		this.stop = true;
	}
}

AutoScroll.prototype.mouseOut = function()
{
	if( this.stop ) {
		this.stop = false;
	}
}