// scrollable.js
// 20070521TM - tracks multiple scrollable regions


// HOWTO:
// In the HEAD should have:
// <script language="JavaScript" type="text/javascript" src="scrollable.js">
// In the BODY should have:
// <body onLoad="Scroll(scrollable_list)">


// JavaScript encapsulates an instance of a scrollable text

function Scrollable(divvy,startpos)
{
	this._divvy = divvy;	// divvy refers to the div of the scrollable text
	this._pos = startpos;			// initial position >= 0
	this._startpos = startpos;			// for repeat if necessary
	this._repeat = true;	// always repeat
	this._delay = 0;	// no delay, or replace this with >0
	this._countdown = 0;	// always reset with _delay
	//alert(divvy.id);
}

var name_scrollable_list = "scrollable_list";	// this is the default name

function Scroll(slist)
{
	//alert(slist.length);
	// list of scrollables
	for (i=0;i<slist.length;i++)
	{
		var sobj;
		//alert(slist);
		sobj = slist[i];
		//alert(sobj._divvy.id);

		if (sobj._countdown <= 0)
		{
			// it is time...

			if (sobj._pos < 0-sobj._divvy.offsetHeight)
			{
				// already scrolled gone
				//alert('done')

				if (sobj._repeat)
				{
					sobj._pos = sobj._startpos;
				}
			}
			else
			{
				sobj._pos -= 1;
				sobj._divvy.style.top = sobj._pos;
			}

			// reset the counter

			sobj._countdown = sobj._delay;
		}
		else
		{
			sobj._countdown --;	// count down
		}

	}
	window.setTimeout("Scroll("+name_scrollable_list+")",10);
}

