/***************
By: MesaRO LLC. (Keith Connolly)
Date: December 1st - December 5th
Description: Fully Javascript image rotator with date and image ranges.
LIBs: jQuery(v1.7.1)
***************/

/*****************
//START SETTINGS
*****************/
//the main directory to prepend to all image url's
var baseURL = "images/seasonal/";
//the time for each rotation
var timeOut = 3000;
var selector = "#mesaSlider";

//arrays, define as  many as you need for each season or block of time.
//It's formatting in an array array's that consist of image/url 
//The naming does not matter but should match the time block ie. summerImages/summerTime
var summerImages = [["summer_rougeca.gif","#"],
	["summer_rougedlh.gif","#"],
	["summer_rouguemh.gif","#"],
	["summer_pointnb.gif","#"],
	["summer_rouguesoha.gif","#"],
	["summer_wildonionsw.gif","#"],
	["summer_simmithf.gif","#"],
	["summer_bellsobr.gif","#"]];
var winterImages = [["winter_bellswwa.gif","#"],
	["winter_bellssa.gif","#"],
	["winter_bellshsa.gif","#"],
	["winter_bellskal.gif","#"],
	["winter_bellsdcs.gif","#"],
	["winter_bellscdb.gif","#"],
	["winter_bellsct.gif","#"],
	["winter_bellshhnf.gif","#"],
	["winter_bellsca.gif","#"],
	["winter_roguemma.gif","#"],
	["winter_roguespra.gif","#"],
	["winter_rogueysipa.gif","#"],
	["winter_pointsbwa.gif","#"],
	["winter_bscwa.gif","#"]];
var fallImages = [["x","#"],
	["fall_bellsbba.gif","#"],
	["fall_bellsoctf.gif","#"],
	["fall_pointoctf.gif","#"],
	["fall_roguedcs.gif","#"],
	["fall_rougejja.gif","#"],
	["fall_summitoctf.gif","#"],
	["fall_wildonionpa.gif","#"]];
var springImages = [["spring_pointeb.gif","#"],
	["spring_summitmb.gif","#"]];

//DO NOT MODIFY THESE
var curr_year = new Date().getFullYear();
var pre_flop, post_flop = new Date();
var today = new Date();
var current_block = 0;
pre_flop = curr_year;
post_flop = curr_year+1;
//END DO NOT MODIFY

//USE PRE FLOP ON A DATE RANGE THAT BEGINS BEFORE THE TURN OF THE YEAR 
//USE POST FLOP ON A DATE RANGE THAT ENDS AFTER THE TURN OF YEAR (like WINTER)

//Change this to the end time of any date that ends in the following year. ie. feb, 19th <-- end of winter
//Winter starts in december and goes till feb, crossing the end of the year.
if (today.getMonth() < 3 && today.getDay() < 20 ){
	pre_flop = curr_year-1;
	post_flop = curr_year;
}

//Change the numbers only, do not change the year setting MM,DD
//replace curr_year with pre_flop and post_flop if the date range is split between two years
var startDate=new Date();
var endDate=new Date();
startDate.setFullYear(curr_year,3,01);
endDate.setFullYear(curr_year,4,30);
var springTime = [startDate,endDate];

var startDate=new Date();
var endDate=new Date();
startDate.setFullYear(curr_year,5,01);
endDate.setFullYear(curr_year,8,31);
var summerTime = [startDate,endDate];

var startDate=new Date();
var endDate=new Date();
startDate.setFullYear(curr_year,9,01);
endDate.setFullYear(curr_year,10,31);
var fallTime = [startDate,endDate];

var startDate=new Date();
var endDate=new Date();
startDate.setFullYear(pre_flop,11,01);
endDate.setFullYear(post_flop,2,28);
var winterTime = [startDate,endDate];

//REMEMBER TO CHANGE THE PRE_ / POST_ FLOP VARIABLES IF YOU CHANGE WHAT DATE RANGE ENDS BETWEEN YEARS.

//arrays, add as many to blocks array as you need for each image and time block(s)
//this links the images with the time, ie. summerImages with summerTime so that the right images
//are displayed during the right time.
var blocks = new Array
blocks[0] = [springImages,summerTime]
blocks[1] = [summerImages,winterTime]
blocks[2] = [fallImages,springTime]
blocks[3] = [winterImages,fallTime]
/****************************
//END Settings
*****************************/

/****************************
//DO NOT EDIT BELOW THIS LINE
*****************************/
function sa(dir){
	if(dir == 0)
		if($(selector+" a:first").is(":visible")){
			$(selector+" a:visible").removeClass("active").hide();
			$(selector+" a:last").fadeIn().addClass("active");
		}else{
			$(selector+" a:visible").removeClass("active").hide().prev().fadeIn().addClass("active");
		}
	else
		if($(selector+" a:last").is(":visible")){
			$(selector+" a:visible").removeClass("active").hide();
			$(selector+" a:first").fadeIn().addClass("active");
		}else{
			$(selector+" a:visible").removeClass("active").hide().next().fadeIn().addClass("active");
		}
	setTimeout("sa("+dir+")",3000);
}

$(document).ready(function() {
	for(i in blocks){
		if(today >= blocks[i][1][0] && today <= blocks[i][1][1]){
			current_block = i;
		}
	}

	for(i in blocks[current_block][0]){
		$(selector).append("<a href='"+blocks[current_block][0][i][1]+"' style='display:none;'><img src='"+baseURL + blocks[current_block][0][i][0]+"'/></a>");
	}
	$(selector+" a:first").fadeIn().addClass("active");
	//BEGIN ROTATION
	setTimeout("sa(0)",timeOut);
});
