/* 
	Tacita Morway
	tacita_morway@wgbh.org
	08.05.08
   ----------------------------------------------------*/

var WeeklyHilites = {

	start: function(){
		// hide all hilites
		var hlts = $ES('li', 'hilites');
		hlts.each(function(item, index) {
			item.className = "hide";
		});
		
		// show this weeks hilite
		WeeklyHilites.show();
	},

	show: function(){
		// Function cycles through the current hilites available, changing which is visible every week.
		// Once we've reached the end of the available hilites, start again at the beginning of the list.
		// Hilites links are defined in the html, with the images are set in the css.

		// count number of hilites available
		var hlts = $ES('li', 'hilites');
	
		if($('hilites').className == "fixed") {
			hlts[0].className = "";		
		} else { 
			// generate the week number from a date object
			Date.prototype.getWeek = function() {
				var jan1 = new Date(this.getFullYear(),0,1);
				return Math.ceil((((this - jan1) / 86400000) + jan1.getDay())/7);  // 86400000 = #milliseconds in a day
			}
			
			var today = new Date();
			var currWk = today.getWeek();
	
			var numHlts = hlts.length;
			
			// determine the index to select from
			var ind = Math.ceil(currWk%numHlts);
			
			// unhide that element
			hlts[ind].className = "";
		}
	}	
	
};

window.addEvent('domready', WeeklyHilites.start);

