function rotatorImage(lastMonth,lastDay,lastYear){
	this.lastDay = lastDay;
	this.lastMonth = lastMonth;
	this.lastYear = lastYear;
	rotator.images.push(this);
}

var rotator = {
	images : [],
	init : function(){
		var index = rotator.findRotateIndex();
		rotator.setImage(index);
	},
	findRotateIndex : function(){
		var today = new Date(),
			currMonth = today.getMonth() + 1,
			currDay = today.getDate(),
			currYear = today.getFullYear(),
			arrLen = rotator.images.length,
			lowestIndex = 0,
			lowestDate;

		for (var i=0;i<arrLen;i++){
			var picMonth = rotator.images[i].lastMonth,
				picDay = rotator.images[i].lastDay,
				picYear = rotator.images[i].lastYear;
			//only select dates that are after today's date.
			if (picYear > currYear || (picMonth > currMonth && picYear === currYear) || (picYear === currYear && picMonth === currMonth && picDay >= currDay)){
				if (typeof lowestDate !== "object"){
					lowestDate = rotator.images[i];
					lowestIndex = i;
				} else {
					if (picYear < lowestDate.lastYear){
						lowestDate = rotator.images[i];
						lowestIndex = i;
					} else if (picYear === lowestDate.lastYear && picMonth < lowestDate.lastMonth){
						lowestDate = rotator.images[i];
						lowestIndex = i;
					} else if (picMonth === lowestDate.lastMonth && picDay <= lowestDate.lastDay && picYear === lowestDate.lastYear){
						lowestDate = rotator.images[i];
						lowestIndex = i;
					}
				}
			}
		}
		return(lowestIndex);
	},
	setImage : function(index){
		$('ul.navigation a:eq(' + index + ')').click();
	}
}

$(function(){
	//For each rotator image, add a "rotatorImage" below using the
	//last date of the show as the parameters. Month first then day.
	
	//So if a show ends on Feb. 21st, 2013 you would create it like this:
	//    new rotatorImage(2,21,2013);
	
	new rotatorImage(8,7,2011);	//Rotator 1
	new rotatorImage(10,23,2011);	//Rotator 2
	new rotatorImage(12,18,2011);	//Rotator 3
	new rotatorImage(3,4,2012);	//Rotator 4
	new rotatorImage(4,1,2012);	//Rotator 5
	new rotatorImage(5,20,2012);	//Rotator 6
	new rotatorImage(8,5,2012);	//Rotator 7
	rotator.init();
});

