/*
Plugin Name: Fancy Archives Reloaded
Plugin URI: http://www.black-cat.it/blog/
*/

if( window.addEventListener ) {
	window.addEventListener( 'load', hideAll, false );
} else {
	window.attachEvent('onload',hideAll);
}

function hideAll() {
	items = document.getElementsByTagName("ul");
	for( i = 0; i < items.length; i++ ) {
		if( items[i].id.indexOf( "fancyArchivesList-" ) == 0 ) {
			year = (new Date()).getYear();
			month = (new Date()).getMonth() + 1;
			if( year < 2000 ) {
				year += 1900;
			}

			items[i].style.display = "none";

			if( fancyarch_exp_curr_year && items[i].id == "fancyArchivesList-" + year ) {
				items[i].style.display = "";
			}

			if( fancyarch_exp_curr_month && items[i].id == "fancyArchivesList-" + year + "-" + month ) {
				items[i].style.display = "";
			}
		}
	}
}

function hideNestedList( e ) {
	if( e.target ) {
		src = e.target;
	}
	else {
		src = window.event.srcElement;
	}

	srcList = src.parentNode;
	childList = null;

	for( i = 0; i < srcList.childNodes.length; i++ ) {
		if( srcList.childNodes[i].nodeName.toLowerCase() == 'ul' ) {
			childList = srcList.childNodes[i];
		}
	}

	if( src.getAttribute( "rel" ) == "hide" ) {
		childList.style.display = "none";
		src.setAttribute("rel","show");
	}
	else {
		childList.style.display = "";
		src.setAttribute("rel","hide");
	}

	if( e.preventDefault ) {
		e.preventDefault();
	}

	return false;
}

