// countdown code v2 (displays via sIFR)

var a = [
	[ [2010,5,1],  'until Nelson Ledges races',		'Nelson Ledges races today'],
	[ [2010,5,2],  'until Nelson Ledges races',		'Nelson Ledges races today'],
	[ [2010,5,15], 'until Grattan races', 			'Grattan races today'],
	[ [2010,5,16], 'until Grattan races', 			'Grattan races today'],
	[ [2010,6,19], 'until BeaveRun races ', 		'BeaveRun races today'],
	[ [2010,6,20], 'until BeaveRun races', 			'BeaveRun races today '],
	[ [2010,7,3], 'until Grattan National races ', 'Grattan National races today'],
	[ [2010,7,4], 'until Grattan National races', 	'Grattan National races today'],
	[ [2010,7,13],  'until RRGCs @ Mid-Ohio', 		'RRGCs @ Mid-Ohio today'],
	[ [2010,7,14],  'until RRGCs @ Mid-Ohio', 		'RRGCs @ Mid-Ohio today'],	
	[ [2010,8,7],  'until Cycle Jam @ VIR', 		'Cycle Jam @ VIR today'],
	[ [2010,8,8],  'until Cycle Jam @ VIR', 		'Cycle Jam @ VIR today'],
	[ [2010,9,4],  'until BeaveRun races', 			'BeaveRun races today'],
	[ [2010,9,5],  'until BeaveRun races', 			'BeaveRun races today'],
	[ [2010,9,25], 'until Nelson Ledges races',		'Nelson Ledges races today'],
	[ [2010,9,26], 'until Nelson Ledges races',		'Nelson Ledges races today'],
	[ [2011,1,1],  'until 2010', 					'Happy New Year!']
]

var today = new Date();
var y = today.getFullYear();
var m = today.getMonth();
var d = today.getDate();
var today0 = new Date(y,m,d);
var txt = '';

for(var i = 0; i < a.length; i++) {
  var date = new Date(a[i][0][0], a[i][0][1]-1, a[i][0][2]);
	if (date - today0 == 0) {
	  txt += a[i][2];
		var theoccasion = date;
		var onOccasionText = txt;
		break;
	}
	else if ((date - today0 > 0) && (txt == "")) {
	  txt += a[i][1];
		var theoccasion = date;
		var beforeOccasionText = txt;
	}
}

// countdown code v2 (displays via sIFR)
var today = new Date();
var countdownOutput = "";
var monthtext = new Array ("Jan", "Feb", "Mar", "April", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec");

var showdate = "(" + monthtext[theoccasion.getMonth()] + " " + theoccasion.getDate() + ")"; // show date of occasion
var one_day = 1000 * 60 * 60 * 24;
var calculatediff = "";

calculatediff = Math.ceil((theoccasion.getTime() - today.getTime()) / (one_day));
if (calculatediff < 0) { // if date already passed
	var nextyeartoday = new Date();
	nextyeartoday.setFullYear(today.getFullYear() + 1);
	calculatediff = Math.ceil((nextyeartoday.getTime() - today.getTime()) / (one_day) + calculatediff);
}

// display message accordingly
var pluraldayornot = (calculatediff == 1) ? "day" : "days";
if ( calculatediff > 0) {
	countdownOutput += '<a href="schedule.php" class="countdown_text" title="View entire schedule"><h4>' + calculatediff + '</h4><p class="countdown_text">' + pluraldayornot + ' ' + beforeOccasionText + '</p></a>';
} else if (calculatediff == 0) {
	countdownOutput += '<a href="schedule.php" class="countdown_text" title="View entire schedule"><h4>0</h4><p class="countdown_text">' + onOccasionText + '</p></a>';
}