//interval determines the speed of the scroller
var intInterval=30;
var intSpeed=1;
var blnPause=1;
var intCopySpeed=intSpeed;
var intPauseSpeed=(blnPause==0)? intCopySpeed: 0;
var intActualWidth;
var divScroller, elmScrollerBox, tblPreviewLinks, elmCounter;
var objTimer;
var blnDev=0;

function populateScrollers(){

	// Get the element
	divScroller = $("scroller");
	
	if (!divScroller) { return false; }
	
	tblPreviewLinks = divScroller.childElements()[0];
	
	// Make sure the necessary element exists
	if (tblPreviewLinks) {
	
		// Double the tds
		tblPreviewLinks.childElements()[0].childElements()[0].update(tblPreviewLinks.childElements()[0].childElements()[0].innerHTML + tblPreviewLinks.childElements()[0].childElements()[0].innerHTML);
		
		tblPreviewLinks.setStyle({
			position: 'absolute',
			left: '0px',
			margin: '0px'
		});
		
		// Make the counter
		if (blnDev) {
			elmCounter = new Element('h2');
			elmCounter.setStyle
			({
				backgroundColor: 'red',
				position:'absolute',
				bottom:'0px',
				right:'0px',
				fontSize:'10px',
				color:'white',
				padding:'10px'
			});
			divScroller.insert(elmCounter,top);
		}
		
		// Observe
		Event.observe(divScroller, 'mouseover', stopScroll);
		Event.observe(divScroller, 'mouseout', startScroll);
		
		// Get the width
		intActualWidth=tblPreviewLinks.getWidth()/2;
		
		// Set it off
		objTimer = setTimeout("scrollmarquee()", intInterval);
	
	}
	
}

function scrollmarquee(){

	// Get the width
	intActualWidth=tblPreviewLinks.getWidth()/2;
	
	// If it is at the mid stage, move it back to the original position
	if (parseInt(tblPreviewLinks.style.left)<((intActualWidth)*(-1))) {
		tblPreviewLinks.style.left="-1px";
	}
	// Keep moving it
	else {
		tblPreviewLinks.style.left=parseInt(tblPreviewLinks.style.left)-intCopySpeed+"px";
	}
	if (blnDev) {elmCounter.update("Time: " + Date() + " <br/>Left: " + tblPreviewLinks.style.left + " <br/>CopySpeed: " + intCopySpeed + " <br/>Test: " + parseInt(tblPreviewLinks.style.left) + " &lt; " + ((intActualWidth)*(-1)))};
	objTimer = setTimeout("scrollmarquee()", intInterval);
}

function stopScroll(){
	intCopySpeed=0;
}
function startScroll(){
	intCopySpeed=1;
}

Event.observe(window, 'load', populateScrollers); 
