var l;
var t;
var w;
var h;

var vpHeight;
var totalHeight;

var vpTop;
var vpBottom;
var vpRight;
var vpLeft;

var scrollInc;
var scrollSpeed;
var scrollPause;
var timer;


function startScroll()
{
	var el=document.getElementById('divScroller');
	clipstring = 'rect('+vpTop+'px,'+vpRight+'px,'+vpBottom+'px,'+vpLeft+')';
	el.style.clip = clipstring;

	scrollit();
}

function pause()
{
	setTimeout('scrollit()',scrollPause)
}

function scrollit()
{
	//the viewport moves down the div so a different part is visible
	//and the div is repositioned higher up the screen so the viewport appears
	//to remain in the same place
	var el=document.getElementById('divScroller');

	if (vpTop==totalHeight-vpHeight)
	{
		//return to start
		vpTop=0;
		vpBottom=vpHeight;
		el.style.top=(parseInt(el.style.top))+((arrEntries.length-1)*vpHeight);
	}

	//show next array entry
	vpTop += scrollInc;
	vpBottom += scrollInc;
	el.style.top=(parseInt(el.style.top))-scrollInc;

	clipstring = 'rect('+vpTop+'px,'+vpRight+'px,'+vpBottom+'px,'+vpLeft+')';
	el.style.clip = clipstring;

	//pause when each entry has scrolled fully into view
	if (vpTop%vpHeight==0)
	{
		clearTimeout(timer);
		pause();
	}
	else
		timer = setTimeout('scrollit()',scrollSpeed);
}

function doScroller(width,height,borderWidth,borderColour,speed,pause)
{
	//initialise
	l=0;
	t=0;
	w=width;
	h=height;

	vpHeight=h;	//vp=viewport
	totalHeight=arrEntries.length*vpHeight;

	vpTop=0;
	vpBottom=vpHeight;
	vpRight=w;
	vpLeft=0;

	scrollInc=10;
	scrollSpeed=speed;
	scrollPause=pause;

	//write scroller to screen
	document.write("<div id=\"outline\" style=\"position:absolute;top:"+(t-borderWidth)+";left:"+(l-borderWidth)+";width:"+(w+(2*borderWidth))+";height:"+(h+(2*borderWidth))+";background-color:"+borderColour+"\"></div>");
	document.write("<div id=\"divScroller\" style=\"position:absolute;top:"+t+";left:"+l+";width:"+w+";height:"+h+";\">");
	document.write("<table cellpadding=0 cellspacing=0 border=0 width="+w+">");

	for (var i=0;i<arrEntries.length;i++)
		document.write("<tr><td class=\"scrollItem\" height="+vpHeight+" align=center valign=center>"+arrEntries[i]+"</td></tr>");

	document.write("</table></div>");

	//start the scroller
	startScroll();
}
