
var Archives_current = false;

function Archives_init() {

	var years = document.getElementById('archive').getElementsByTagName('ul');
	
	var n = 0;
	for ( i=0; i<years.length; i++ ) {
		
		if(years[i].className == 'months-list' ) {
		
			var parts = years[i].id.split('-');
			var year = parts[1];

			if( n != 0 ) {
				years[i].style.display = "none";
			}
			else {
				Archives_current = years[i].id;
			}
			
			document.getElementById('toggle-year-' + year).onclick = function() {
				var parts = this.id.split('-');
				var year = parts[2];
				if( Archives_displayMonths('months-' + year ) ) {
					return false;
				}
				else {
					 // If current year is already open,
					 // the second click will send the user
					 // to the archive for this year
					return true;
				}
			}
		}
		n++;
	}
}

function Archives_displayMonths( id ) {
	if( id != Archives_current ) {
		if( Archives_current ) {
			document.getElementById( Archives_current ).style.display = "none";
		}
		document.getElementById( id ).style.display = "block";
		Archives_current = id;
		return true;
	}
	else {
		return false;
	}
}


if (window.addEventListener)
	window.addEventListener("load", Archives_init, false);
else if (window.attachEvent && !window.opera)
	window.attachEvent("onload", Archives_init);


