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

function Timer()
{
	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.

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

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

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

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

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

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

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

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

/****** News box div rotation ******/
var nContentSetCurrentShown=1;
var nContentSetTicker; //declare the ticker variable as a global

function contentSetTicker()
{
	this.count = 0;
	this.timer = new Timer(this);
	this.clicked = false;
}

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

function showContentSetDiv(thediv)
{
	// Hide div and dim menu link
	document.getElementById('ContentSetDiv'+nContentSetCurrentShown).className='ContentSetHidden';

	// Show next div and highlight menu link
	document.getElementById('ContentSetDiv'+thediv).className='ContentSetVisible';

	nContentSetCurrentShown=thediv;
}

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

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

function rotatingContentSetInit ()
{
	nContentSetTicker = new contentSetTicker();
	nContentSetTicker.tick(1);
}
