var SCROLLER_HEIGHT; // height of the scrolling window
var SCROLLER_WIDTH;

var scrolltimer;  // pointers to timer objects
var base_top;     // the "top" value of the scrolling window
var height;       // the height of the complete content
var div;		   // pointer to object.style
var top;		   // the actual "top" value of the moving div

function Scroll() {
	if(height <= SCROLLER_HEIGHT)
		return; // we don't need to scroll here...
	
	// compute new position
	var c_top = base_top-top+1;
	var c_bot = c_top+SCROLLER_HEIGHT;
	top=top-1;
	
	// if we hitted the bottom...
	if(top<=(base_top-height-SCROLLER_HEIGHT)){
		// ... roll again!
		top = base_top;
		c_top = 0;
		c_bot = SCROLLER_HEIGHT;
	}
	
	// set new position	
	if(document.layers){ // netscape...
		div.top=top;
		div.clip.top = c_top;
		div.clip.bottom = c_bot;
	} else {
		div.clip = "rect("+c_top+"px "+SCROLLER_WIDTH+"px "+c_bot+"px 0px)";
		div.top=top+'px';
	}
		
	scrolltimer = setTimeout("Scroll()", 100);
}

function stopScroll() {
	if(scrolltimer!=null){
		clearTimeout(scrolltimer);
		scrolltimer=null;
	}
}

/**
 * @param ident the element id
 * @param init_top the original element's top (int)
 * @param scrollerWidth
 * @param scrollerHeight
 */
function scroll_init(ident,init_top,scrollerWidth,scrollerHeight){
	SCROLLER_WIDTH = scrollerWidth;
	SCROLLER_HEIGHT = scrollerHeight;
	
	if (document.layers) {
		div = eval("document."+ident);  // netscape 4
		height = eval("document."+ident+".offsetHeight");
	} else if (document.getElementById) {
		div = eval("document.getElementById('"+ident+"').style");  // DOM level2 compliant
		height = eval("document.getElementById('"+ident+"').offsetHeight");
	} else if (document.all) {
		div = eval("document.all."+ident+".style"); // IE 5+
		height = eval("document.all."+ident+".offsetHeight");
	}
	
	if(div!=null){
		if(height > SCROLLER_HEIGHT)
			// add a blank between two rolling loops
			div.padding = SCROLLER_HEIGHT+"px 0 0 0";
	
		base_top=init_top;
		top=init_top;
		Scroll();
	}
}