/*
Fancy Archives ver 0.5
Copyright 2006 Andrew Rader

This file is part of Fancy Archives

    Fancy Archives is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Fancy Archives is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Fancy Archives; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

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;
}
