/*	ticker.js

	Scrolling ticker
*/


//	get the style sheet
document.write('<link rel="stylesheet" href="/javascripts/Ticker.css" type="text/css" />');


//	*** Ticker object ***

function Ticker( id, shiftBy, interval)
{
	this.id       = id;
	this.shiftBy  = shiftBy ? shiftBy : 1;
	this.interval = interval ? interval : 20;
	this.previnterval = this.interval;
	this.runId	= null;
	this.div = document.getElementById(id);

	var node = this.div.firstChild;
	var next;
	while (node)
	{
		next = node.nextSibling;
		if (node.nodeType == 3) this.div.removeChild(node);	//	3 = TEXT_NODE
		node = next;
	}

	this.left = this.div.parentNode.offsetWidth;	//	scroll in from the right
	this.shiftLeftAt = this.div.firstChild.offsetWidth;
	this.div.style.height	= this.div.firstChild.offsetHeight;
	this.div.style.width = 2 * screen.availWidth;
	
	if (this.div.childNodes.length == 1) 
	{	//	duplicate the node, or it will scroll out fully before 'jumping' back in
		this.div.appendChild( this.div.firstChild.cloneNode(true));
	}
	//	ok, good to go
	this.div.style.visibility = 'visible';
}	//	Ticker

function startTicker()
{
	this.stop();
	this.left -= this.shiftBy;
	if (this.left <= -this.shiftLeftAt)
	{
		this.left = 0;
		this.div.appendChild(this.div.firstChild);
		this.shiftLeftAt = this.div.firstChild.offsetWidth;
	}
	this.div.style.left = (this.left + 'px');
	this.runId = setTimeout(this.start.bind(this), this.interval);	//	bind is mootools feature
}	//	startTicker

function stopTicker()
{
	if (this.runId) clearTimeout(this.runId);
	this.runId = null;
}

function changeTickerInterval(newinterval)
{
	if (typeof(newinterval) == 'string') newinterval = parseInt('0' + newinterval, 10);
	if (typeof(newinterval) == 'number' && newinterval > 0)
	{	this.previnterval = this.interval;
		this.interval = newinterval;
		this.stop();
		this.start();
	}
}	//	changeTickerInterval

function slowTicker()
{	this.changeInterval( 6 * this.interval);
}

function goTicker()
{	this.changeInterval( this.previnterval);
}

Ticker.prototype.start = startTicker;
Ticker.prototype.stop = stopTicker;
Ticker.prototype.changeInterval = changeTickerInterval;
Ticker.prototype.slow = slowTicker;
Ticker.prototype.go = goTicker;

//	*** end of Ticker object ***


function startticker( tickerID, interval)
{	var tckr = null;

	if (document.getElementById( tickerID))
	{	tckr = new Ticker( tickerID, 1, interval); // interval regelt de snelheid
		tckr.start();
	}
	return tckr;
}


// ***	copy and adjust the part below when you need more tickers on one page,
//		and/or use different variable name or ID

var ticker = null;

// activate dynamic part _after_ page has loaded completely
if (window.addEvent)	//	addEvent is mootools feature
{	window.addEvent( 'domready', function(){ ticker = startticker('tickerID', 20);});
}
