var bannerDir = 'http://media.thestate.com/images/gogamecocks/';

function gameInfo(gameBanner, gameTime) {
	this.gameBanner = gameBanner;
	this.gameTime = gameTime;
}

var gameArray = new Array();
/* Format: new  gameInfo('helmet_id', new Date('date here')); */
gameArray[0] =  new gameInfo('2010cwsgame6',	        new Date('June 28, 2010 19:30:00'));	    // 2010cwsgame6
gameArray[1] =  new gameInfo('2010cwsgame7',	        new Date('June 29, 2010 19:30:00'));	    // 2010cwsgame7
gameArray[2] =  new gameInfo('3SouthernMiss2010',	        new Date('September 2, 2010 19:30:00'));	    // 3SouthernMiss2010



$(function() {
	setInterval(function() {
		var time = new Date();
		var now = time.getTime();
		var thisGameTime;

		for (var i = 0; i < gameArray.length; i++) {
			thisGameTime = gameArray[i].gameTime.getTime();
			if (now < thisGameTime) {
				var diff = Math.abs(thisGameTime - now);
				break;
			} else if ($('#gamedayblock').css('display') == 'block') {	
				if ((now - thisGameTime) < 86400000) {
					var diff = 0;
					break;
				}
			}
		}

		var bannerFile = bannerDir + gameArray[i].gameBanner + '.png';
		if ($('#nextgame').attr('src') != bannerFile) {
			$('#nextgame').attr('src', bannerFile);
		}

		var days = Math.floor(diff / 86400000);
		var hours = Math.floor(diff / 3600000) % 24;
		var minutes = Math.floor(diff / 60000) % 60;
		var seconds = Math.floor(diff / 1000) % 60;
		
		$('#days2').html(timerFormat(Math.floor(days / 100)));
		$('#days1').html(timerFormat(Math.floor((days % 100) / 10)));
		$('#days0').html(timerFormat(days % 10));		
		$('#hours1').html(timerFormat(Math.floor(hours / 10)));
		$('#hours0').html(timerFormat(hours % 10));		
		$('#mins1').html(timerFormat(Math.floor(minutes / 10)));
		$('#mins0').html(timerFormat(minutes % 10));		
		$('#secs1').html(timerFormat(Math.floor(seconds / 10)));
		$('#secs0').html(timerFormat(seconds % 10));
	}, 100);
});

function timerFormat(num) {	return (num) ? num : '0'; }

