window.onload=function() {

	init();

}

if (document.getElementById){
document.write('<style type="text/css">');
document.write('.switchcontent{display:none;}');
document.write('</style>');
}



function checkState(currentImage) {	
		if(currentImage.match("over") != null) {
			return "_over.gif";
		} else if(currentImage.match("active") != null) {
			return "_active.gif";
		}
		return ".gif";
}

function goAnchor(theMonth, theDay) {

	// force numbers
	theMonth = Number(theMonth);
	theDay = Number(theDay);


	// close all divs
	for(i = 0; i < document.getElementsByTagName("div").length; i++) {
		currentStyle = document.getElementsByTagName("div")[i].style.display;
		if(currentStyle == "block") {
			document.getElementsByTagName("div")[i].style.display = "none";
		}
	}

	if(theMonth == 0 && theDay == 0) {
		// do nothing
		
		return 0;
	} else if(theMonth > 0 && theDay == 0) {
		// just jump to the month

		document.getElementById("content" + theMonth).style.display="block";
		if(navigator.userAgent.indexOf('Safari') == -1) { // safari doesn't like this
			document.location = "#top";
		}
		selectgif(theMonth);
		
		return 1;
		
	} else if(theMonth > 0 && theDay > 0) {
		// jump to the next anchor
		for(i = 0; i < document.anchors.length; i++) {
			thisAnchor = document.anchors[i].name;
			thisMonth = thisAnchor.substring(5,7);
			thisDay = thisAnchor.substring(8,10);
			if(thisMonth != 0 && thisDay != 0) {
			 // hack: quick convert to string
			 	tempDay = ""
				if(theDay < 10) {
					tempDay = "0" + theDay;
				} else {
					tempDay = "" + theDay
				}

				compare1 = Number(thisMonth + thisDay);
				compare2 = Number(theMonth + "" + tempDay);

				if( compare1 >= compare2) {
	
						matchAnchor =  "date_" + thisMonth + "_" + thisDay;
						document.getElementById("content" + Number(thisMonth)).style.display="block";
						if(navigator.userAgent.indexOf('Safari') == -1) { // safari doesn't like this
							document.location = "#" + matchAnchor;
						}
						
						selectgif(Number(thisMonth));
						
						return 1;
				}
			}
		}

	}

	return 0;
}

function selectgif(theMonth) {

	for(i = 0; i < document.getElementsByTagName("img").length; i++) {
		currentImage = document.getElementsByTagName("img")[i].src;
		document.getElementsByTagName("img")[i].src = currentImage.replace(checkState(currentImage),".gif");
	}
	
	imageToSwap = document.getElementById("date" + theMonth).src;
	document.getElementById("date" + theMonth).src = imageToSwap.replace(checkState(imageToSwap),"_active.gif");
	document.getElementById("date" + theMonth + "_1").src = imageToSwap.replace(checkState(imageToSwap),"_active.gif");

}

function dateSelect(date) {

	if(date == 0) {
	var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();		
		goAnchor(month,day);
	} else {
		goAnchor(date,0)
	}
	
}

function dateOver(date) {
	imageToSwap = document.getElementById("date" + date).src;
 	if(checkState(imageToSwap) == ".gif") {
		document.getElementById("date" + date).src = imageToSwap.replace(checkState(imageToSwap),"_over.gif");
		document.getElementById("date" + date + "_1").src = imageToSwap.replace(checkState(imageToSwap),"_over.gif");
	}
}

function restore() {
	for(i = 0; i < document.getElementsByTagName("img").length; i++) {
		currentImage = document.getElementsByTagName("img")[i].src;
		if(checkState(currentImage) != "_active.gif") {
		document.getElementsByTagName("img")[i].src = currentImage.replace(checkState(currentImage),".gif");
		}
	}
}

function init() {
	urlquery=location.href.split("?");
	rnurlterms=urlquery[1].split("#");
	if(rnurlterms[1]!=null) {
		theAnchor = rnurlterms[1];
		if(theAnchor.substring(0,4) == "date") {
			month = Number(theAnchor.substring(5,7));
			day = Number(theAnchor.substring(8,10));
			goAnchor(month,day);
		} else {
			dateSelect(0);
		}
	} else {
		dateSelect(0);
	}
	montre();
}

