var currentGAMEOffset = 0;
var now;

function getNow()
{
	now = new Date();

//var tzround=Math.round(now.getTimezoneOffset()/60)
var tz=(now.getTimezoneOffset()/60)
//alert(tz);

now.setTime(now.getTime() + 10 * 60 * 60 * 1000);

}

getNow();

function GAMEArrayItem(n, d)
{
	this.name = n;
	this.start = new Date(d);
	this.end = new Date;
	this.end.setTime(this.start.getTime() + 4 * 60 * 60 * 1000);
	this.countdown = new Date(0);
	this.inProgress = false;

	return this;
}

function GAMECurrent()
{
	var i, ret;
		
	for (i = currentGAMEOffset; i < nrl_round.length; i++)
	{
		ret = nrl_round[i];
		ret.countdown = new Date(ret.start - now);
		
		if (ret.start > now)
		{
			ret.inProgress = false;
			currentGAMEOffset = i;
			return ret;
		}
		else if (ret.end >= now)
		{
			ret.inProgress = true;
			currentGAMEOffset = i;
			return ret;
		}
	}

	currentGAMEOffset = i;
}
var nrl_round = new Array();
nrl_round[0] = new GAMEArrayItem("rnd1", "March 12, 2010 18:30:00 GMT");
nrl_round[1] = new GAMEArrayItem("rnd2", "March 19, 2010 18:30:00 GMT");
nrl_round[2] = new GAMEArrayItem("rnd3", "March 26, 2010 18:30:00 GMT");
nrl_round[3] = new GAMEArrayItem("rnd4", "April 02, 2010 13:00:00 GMT");
nrl_round[4] = new GAMEArrayItem("rnd5", "April 09, 2010 19:30:00 GMT");
nrl_round[5] = new GAMEArrayItem("rnd6", "April 16, 2010 19:30:00 GMT");
nrl_round[6] = new GAMEArrayItem("rnd7", "April 23, 2010 19:30:00 GMT");
nrl_round[7] = new GAMEArrayItem("rnd8", "April 30, 2010 19:30:00 GMT");
nrl_round[8] = new GAMEArrayItem("rnd9", "May 08, 2010 19:25:00 GMT");
nrl_round[9] = new GAMEArrayItem("rnd10", "May 14, 2010 19:30:00 GMT");
nrl_round[10] = new GAMEArrayItem("rnd11", "May 21, 2010 19:30:00 GMT");
nrl_round[11] = new GAMEArrayItem("soo1", "May 26, 2010 19:55:00 GMT");
nrl_round[12] = new GAMEArrayItem("rnd12", "May 28, 2010 19:30:00 GMT");
nrl_round[13] = new GAMEArrayItem("rnd13", "June 04, 2010 19:30:00 GMT");
nrl_round[14] = new GAMEArrayItem("rnd14", "June 11, 2010 19:30:00 GMT");
nrl_round[15] = new GAMEArrayItem("soo2", "June 16, 2010 19:55:00 GMT");
nrl_round[16] = new GAMEArrayItem("rnd15", "June 18, 2010 18:55:00 GMT");
nrl_round[17] = new GAMEArrayItem("rnd16", "June 25, 2010 19:30:00 GMT");
nrl_round[18] = new GAMEArrayItem("rnd17", "July 02, 2010 19:30:00 GMT");
nrl_round[19] = new GAMEArrayItem("soo3", "July 07, 2010 19:55:00 GMT");
nrl_round[20] = new GAMEArrayItem("rnd18", "July 09, 2010 19:30:00 GMT");
nrl_round[21] = new GAMEArrayItem("rnd19", "July 16, 2010 19:30:00 GMT");
nrl_round[22] = new GAMEArrayItem("rnd20", "July 23, 2010 19:30:00 GMT");
nrl_round[23] = new GAMEArrayItem("rnd21", "July 30, 2010 19:30:00 GMT");
nrl_round[24] = new GAMEArrayItem("rnd22", "August 06, 2010 19:30:00 GMT");
nrl_round[25] = new GAMEArrayItem("rnd23", "August 13, 2010 19:30:00 GMT");
nrl_round[26] = new GAMEArrayItem("rnd24", "August 20, 2010 19:30:00 GMT");
nrl_round[27] = new GAMEArrayItem("rnd25", "August 27, 2010 18:00:00 GMT");
nrl_round[28] = new GAMEArrayItem("rnd26", "September 03, 2010 19:30:00 GMT");
nrl_round[29] = new GAMEArrayItem("rnd27", "September 10, 2010 19:30:00 GMT");
//nrl_round[30] = new GAMEArrayItem("rnd28", "September 18, 2010 19:30:00 GMT");
//nrl_round[31] = new GAMEArrayItem("rnd29", "September 25, 2010 19:30:00 GMT");
//nrl_round[32] = new GAMEArrayItem("rnd30", "October 04, 2010 16:00:00 GMT");


function getClockImage(s)
{
	var x;
	x = new Image();
	x.src = "graphics/cd/" + s + ".gif";
	
	return x;
}
	
var clockImage = new Array();
for (i = 0; i <= 9; i++)
	clockImage[i] = getClockImage("0" + i);
	//clockImage[i] = getClockImage("img" + i);

clockImage[10] = getClockImage("dotdot");
//clockImage[10] = getClockImage("imgspc");

function drawCountdown()
{
//var roundset = GAME.name;
//document.form.roundno.value=GAME.name;																	 HEIGHT="10"
return '\
<span id=gameon style="display:none">\
<table border="0" cellpadding="0" cellspacing="0">\
	<tr>\
		<td>\
		<table border="0" cellpadding="0" cellspacing="0" BGCOLOR="#000000">\
			<tr>\
				<td><img src="graphics/cd/topleft.gif" width="21" height="13"></td>\
			</tr>\
			<tr>\
				<td><img src="graphics/cd/closed.gif" width="21" height="24"></td>\
			</tr>\
		</table>\
		</td>\
		<td>\
		<table border="0" cellpadding="0" cellspacing="0" BGCOLOR="#000000">\
			<tr>\
				<td><img src="graphics/cd/top_strip_1dc.gif" width="119" height="13"></td>\
			</tr>\
			<tr>\
				<td HEIGHT="17" align="center"><FONT SIZE="2" FACE="Verdana,Arial"><!-- &nbsp;Tipping --><FONT COLOR="#DD1111"><B>CLOSED&nbsp;&nbsp;</B></td>\
			</tr>\
			<tr>\
				<td><img src="graphics/cd/bottom_strip.gif" width="119" height="7"></td>\
			</tr>\
		</table></td>\
		<td><IMG SRC="graphics/cd/right_strip.gif"></td>\
	</tr>\
</table>\
</span>\
\
<span id=countdown style="display:block">\
<table border="0" cellpadding="0" cellspacing="0">\
	<tr>\
		<td>\
		<table border="0" cellpadding="0" cellspacing="0">\
			<tr>\
				<td><img src="graphics/cd/topleft.gif" width="21" height="13"></td>\
			</tr>\
			<tr>\
				<td><img src="graphics/cd/open.gif" width="21" height="24"></td>\
			</tr>\
		</table>\
		</td>\
		<td>\
		<table border="0" cellpadding="0" cellspacing="0">\
			<tr>\
				<td><img src="graphics/cd/topmid.gif" width="119" height="13"></td>\
			</tr>\
			<tr>\
				<td HEIGHT="17"><img src="graphics/spacer.gif" width="13" height="17" name="cdd1"><img src="graphics/spacer.gif" width="13" height="17" name="cdd2"><img src="graphics/cd/dotdot.gif" width="5" height="17"><img src="graphics/spacer.gif" width="13" height="17" name="cdh1"><img src="graphics/spacer.gif" width="13" height="17" name="cdh2"><img src="graphics/cd/dotdot.gif" width="5" height="17"><img src="graphics/spacer.gif" width="13" height="17" name="cdm1"><img src="graphics/spacer.gif" width="13" height="17" name="cdm2"><img src="graphics/cd/dotdot.gif" width="5" height="17"><img src="graphics/spacer.gif" width="13" height="17" name="cds1"><img src="graphics/spacer.gif" width="13" height="17" name="cds2"></td>\
			</tr>\
			<tr>\
				<td><img src="graphics/cd/bottom_strip.gif" width="119" height="7"></td>\
			</tr>\
		</table></td>\
		<td><IMG SRC="graphics/cd/right_strip.gif"></td>\
	</tr>\
</table>\
</span>\
\
<span id=endseason style="display:none"><img src="graphics/cd/season_over.gif" width="119" height="37" alt="Season is over"></span>\
'
}

function setVisibility(o, b)
{
	if (document.getElementById)
		v = document.getElementById(o).style;
	else if (document.all)
		v = document.all[o].style;
	else
		return;
		
	v.display = (b)?"block":"none";
}

function updateClock()
{
	getNow();
	
	var GAME = GAMECurrent();
	if (GAME)
	{
		setVisibility("gameon", false);
		setVisibility("endseason", false);
		setVisibility("countdown", true);

//		document.images.rndno.src = "graphics/cd/" + GAME.name + ".gif";
//		document.images.rndno2.src = "graphics/cd/" + GAME.name + ".gif";

		if (!GAME.inProgress)
		{	var x, y;
			x = Math.floor(GAME.countdown / 1000);
			y = x % 60;
			document.images.cds1.src = clockImage[Math.floor(y / 10)].src;
			document.images.cds2.src = clockImage[y % 10].src;

			x = Math.floor(x / 60);
			y = x % 60;
			document.images.cdm1.src = clockImage[Math.floor(y / 10)].src;
			document.images.cdm2.src = clockImage[y % 10].src;

			x = Math.floor(x / 60);
			y = x % 24;
			document.images.cdh1.src = clockImage[Math.floor(y / 10)].src;
			document.images.cdh2.src = clockImage[y % 10].src;

			x = Math.floor(x / 24);
			y = x % 100;
			document.images.cdd1.src = clockImage[Math.floor(y / 10)].src;
			document.images.cdd2.src = clockImage[y % 10].src;
		}
		else
		{
			setVisibility("gameon", true);
			setVisibility("endseason", false);
			setVisibility("countdown", false);
		}
	}
	else
	{	
		//document.images.cdGAME.src = "graphics/spacer.gif";

		setVisibility("gameon", false);
		setVisibility("endseason", true);
		setVisibility("countdown", false);
	}

	setTimeout("updateClock()", 1000);
}

document.write(drawCountdown());
updateClock();
