/****** TimerTick stuff for div rotation below ******/
// The constructor should be called with the parent object (optional, defaults to window)

function TimerTick()
{
	this.obj = (arguments.length)?arguments[0]:window;
	return this;
}

// The set functions should be called with:
// - The name of the object method (as a string) (required)
// - The millisecond delay (required)
// - Any number of extra arguments, which will all be passed to the method when it is evaluated.

TimerTick.prototype.setInterval = function(func, msec)
{
	var i = TimerTick.getNew();
	var t = TimerTick.buildCall(this.obj, i, arguments);
	TimerTick.set[i].timer = window.setInterval(t,msec);
	return i;
}

TimerTick.prototype.setTimeout = function(func, msec)
{
	var i = TimerTick.getNew();
	TimerTick.buildCall(this.obj, i, arguments);
	TimerTick.set[i].timer = window.setTimeout("TimerTick.callOnce("+i+");",msec);
	return i;
}

// The clear functions should be called with
// the return value from the equivalent set function.

TimerTick.prototype.clearInterval = function(i)
{
	if(!TimerTick.set[i]) return;
	window.clearInterval(TimerTick.set[i].timer);
	TimerTick.set[i] = null;
}

TimerTick.prototype.clearTimeout = function(i)
{
	if(!TimerTick.set[i]) return;
	window.clearTimeout(TimerTick.set[i].timer);
	TimerTick.set[i] = null;
}

// Private data
TimerTick.set = new Array();
TimerTick.buildCall = function(obj, i, args)
{
	var t = "";
	TimerTick.set[i] = new Array();
	if(obj != window)
	{
		TimerTick.set[i].obj = obj;
		t = "TimerTick.set["+i+"].obj.";
	}
	t += args[0]+"(";
	if(args.length > 2)
	{
		TimerTick.set[i][0] = args[2];
		t += "TimerTick.set["+i+"][0]";
		for(var j=1; (j+2)<args.length; j++)
		{
			TimerTick.set[i][j] = args[j+2];
			t += ", TimerTick.set["+i+"]["+j+"]";
		}
	}
	t += ");";
	TimerTick.set[i].call = t;
	return t;
}

TimerTick.callOnce = function(i)
{
	if(!TimerTick.set[i]) return;
	eval(TimerTick.set[i].call);
	TimerTick.set[i] = null;
}

TimerTick.getNew = function()
{
	var i = 0;
	while(TimerTick.set[i]) i++;
	return i;
}

/****** Ticker box div rotation ******/
var nTickerBoxCurrentShown=1;
var nTickerBoxTicker; //declare the ticker variable as a global

function tickerBoxTicker()
{
	this.count = 0;
	this.timer = new TimerTick(this);
	this.clicked = false;
}

tickerBoxTicker.prototype.tick = function(d)
{
	if(!this.clicked)
	{
		// if we've hit the last tab, select the first tab again
		if (d > 6)
		{ d = 1 }
		showFrontTopRotatingTickerBoxDiv(d);
		d++;
		this.timer.setTimeout("tick", 5000, d);
	}
	else
	{
		// get the selected div ID as a starting point for when we start again
		d=nTickerBoxCurrentShown;
		this.timer.setTimeout("tick", 5000, d);
	}
}

function showFrontTopRotatingTickerBoxDiv(thediv)
{
	// Hide div and dim menu link
	document.getElementById('FrontTopTicker'+nTickerBoxCurrentShown).className='FrontRotatingMainTickerBoxHidden';
	document.getElementById('FrontTopRotatingTickerBoxDiv'+nTickerBoxCurrentShown).className='FrontTopRotatingTickerBoxHidden';
	document.getElementById('FrontTopRotatingTickerBoxLink'+nTickerBoxCurrentShown).className='FrontTopRotatingTickerBoxLinkOff';
	document.getElementById('FrontTopRotatingTickerBoxItem'+nTickerBoxCurrentShown).className='FrontTopRotatingTickerBoxItem';


	// Show next div and highlight menu link
	document.getElementById('FrontTopTicker'+thediv).className='FrontRotatingMainTickerBoxVisible';
	document.getElementById('FrontTopRotatingTickerBoxDiv'+thediv).className='FrontTopRotatingTickerBoxVisible';
	document.getElementById('FrontTopRotatingTickerBoxLink'+thediv).className='FrontTopRotatingTickerBoxLinkOn';
	document.getElementById('FrontTopRotatingTickerBoxItem'+thediv).className='FrontTopRotatingTickerBoxItemOn';


	nTickerBoxCurrentShown=thediv;
}

function tickerBoxControlTab(action) //actions are: play, stop
{
	// if the tabs are playing...
	if(action == "play")
	{ nTickerBoxTicker.clicked = false; } // pause them

	// otherwise, if the tabs are paused...
	else if(action == "stop")
	{ nTickerBoxTicker.clicked = true; } // play them
}

function rotatingTickerBoxInit ()
{
	nTickerBoxTicker = new tickerBoxTicker();
	nTickerBoxTicker.tick(1);
}