/* This file is Copyright (c) 2007-2008, Bruce Martin.
Permission to use this file is granted for sole use with Agenda.
*/
var calRedirect= { 

init: function(){
//Replace the date values/File names less the .html extention. 
// So we can get a reliable sort.

var availMonths = new Array("200908","200909","200910","200912","201001","201003");
var useDelay = 2000;
var mode= "auto";
var sortedAvails = availMonths.sort(calRedirect.numcompare);
var monthNums = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
var today = new Date();
var month= monthNums[today.getMonth()];
var year = today.getFullYear();
var currentMonth = year+month;
var goToPage = calRedirect.findInArray(currentMonth,sortedAvails);
if(goToPage == null){
	goToPage = calRedirect.getLastMonth(currentMonth,sortedAvails);
}
if(mode == "auto"){
	if(useDelay > 0){
		var int=self.setTimeout("calRedirect.goToMonthView('"+goToPage+"')",useDelay);
		
	}else {
		calRedirect.goToMonthView(goToPage);
	}
}
},
goToMonthView: function(pGoToPage){
window.location.href=pGoToPage;
},

numcompare: function (a,b){
return a-b;
},

findInArray: function(pStr,pArray)
{

	for (x in pArray)
	{
		if(pArray[x].match(pStr))
		{
			return pArray[x]+".html";
		}
	}
	return null;
},
getLastMonth: function (pCurrentMonth,pSortedAvails){
var tTempAvails = pSortedAvails;
tTempAvails.push(pCurrentMonth);
	var miniMonths = tTempAvails.sort(calRedirect.numcompare);;
	for(tIndex=0;tIndex< miniMonths.length;tIndex++){
		if(miniMonths[tIndex] == pCurrentMonth){
			var theLast = tIndex-1;
			if(theLast < 0){//There isn't a cal prior to the current Month.
             theLast=tIndex+1;}
			var lastPage=miniMonths[theLast]+".html";
			return lastPage;
		}
	}
	return null;	
},
getAvailMonth: function(pCurrent,pAvailMonths){
	for(i=0;i< pAvailMonths.length;i++){
		if(pAvailMonths[i] == pCurrent){
			return pCurrent;
		}
	}
}
};
Core.start(calRedirect);