// The bulk of this script was copied from the Yourtown/Hyperlocal Things To Do cal,
// modified slightly to exist outside the HL shell.
				
var gbDay=0;var gbDate;var gbYear;var gbMonth;var gbMonNum=0;var calCount=0;var dte;var tmpCalCode="";var OmniCount=1; var p1container="";
var ldays = new Array("jan",31,"feb",28,"mar",31,"apr",30,"may",31,"jun",30,"jul",31,"aug",31,"sep",30,"oct",31,"nov",30,"dec",31);
var wdays = new Array("sun","mon","tue","wed","thu","fri","sat");
var killp1 = 0;

function dAdd(x){
	x=parseInt(x);
	if(x>23){
		for(i=0;i<ldays.length-1;i+=2){
			if(dte[1].substring(0,3)==ldays[i]){endDay=ldays[i+1]};
		}
		if(x==endDay){tmp=1;gbMonNum++}else{tmp=x+1}
	}else{ tmp = x+1; }
	return tmp;
}

function wAdd(x){
	if(x<6){tmp = parseInt(x)+1}
	else{tmp=0}
	return tmp;
}

function renderCal(){
	if(calCount<5){
		if((gbDay==0)||(gbDay==6)){dColor="_green"}
		else{dColor="_white"}
		if(gbDate<10){padzero = "0"}
		else{padzero = ""}
        if(killp1==1){p1container = ""}
        else{p1container="&amp;p1=Well_ThingsToDo_DayIcon" + OmniCount}
        if (gbMonNum == '12') {gbYear = '2008'}
        else{gbYear = '2009'}
        if (gbMonNum == '13') {gbMonNum = '01'}
        else {gbMonNum = gbMonNum}
		tmpCalCode+="<td class='calCell'><a href='http://calendar.boston.com/search?swhere=Boston%2CMA" + "&amp;swhat=photography&amp;sort=1&amp;trim=1&amp;srad=100&amp;swhen=" + gbMonNum +"%2F" + gbDate + "%2F" + gbYear + "&amp;st=event" + p1container + "&amp;p12=" + var5 + "TTDwell_dayicon" + OmniCount + "'><img class='date' src='http://cache.boston.com/universal/site_graphics/ttd_hypercalimages/"+padzero+gbDate+dColor+".gif'><br><img class='day' src='http://cache.boston.com/universal/site_graphics/ttd_hypercalimages/"+wdays[gbDay]+".gif'></a></td>";
		gbDate = dAdd(gbDate);
		gbDay = wAdd(gbDay);
		calCount++;
		OmniCount++;
		renderCal();
	}else{
		document.write("<table align='center' border='0' cellpadding='0' cellspacing='0'><tr>"+tmpCalCode+"</tr></table>");
	}
}

function initCal(){
	CalDate=CalDate.toLowerCase()
	if(CalDate.indexOf(":")==-1){
		dte=CalDate.split("|")
	}else{
		dte=new Array();
		tmpDte=CalDate.split("-");
		dte[0]=tmpDte[0].substring(0,3);
		dte[1]=tmpDte[1];
		dte[3]=tmpDte[2].substring(0,4);
		tmpDte=tmpDte[0].split(", ");
		dte[2]=tmpDte[1];
	}
	if((dte[3] % 4)==0){ldays[3]=29}
	for(i=0;i<wdays.length;i++){
		if(dte[0].substring(0,3)==wdays[i]){gbDay=i};
	}
        if(dte[2].indexOf("0")==0){dte[2]=dte[2].charAt(1)}
	gbDate=parseInt(dte[2]);
	gbMonth=dte[1];
	gbYear=dte[3];
	for(i=2;i<ldays.length-1;i+=2){
		if(gbMonth.substring(0,3)==ldays[i]){gbMonNum=i/2};
	}
	gbMonNum++;
	renderCal();
}

initCal();