function close_all() {
	for (i=0; i < $$('.navchild').length; i++) {
		var section = $$('.navchild')[i];
		if ( section.visible() ) {
			new Effect.BlindUp(section, {duration: 0.2, queue: 'end'});
			//section.hide();
		}
	}
}

function show_section() {
	// only use this from navparent elements
	if ( this.className.indexOf('navparent') == -1 ) return false;
	
	// locate the section in question
	section = this.nextSiblings()[0];
	if ( section.className.indexOf('navchild') == -1 ) return false;
	close_all();
	new Effect.BlindDown(section, {duration: 0.2, queue: 'end'});
	//section.show()
	
	return false;
}

function leftnav_init() {
	
	// hide every section (navchild)
	for (i=0; i < $$('.navchild').length; i++) {
		var section = $$('.navchild')[i];
		section.hide();
	}

	// attach onclicks to all navparents
	for (i=0; i< $$('.navparent').length; i++) {
		var parent = $$('.navparent')[i];
		parent.onclick = show_section;
	}
	
	// show the navchild for the current page, based on the 
	// value in the section-id element
	var section = $('section-id').innerHTML;
	if (! section || ! $(section) ) return;
	$(section).show();
}

function select_banner() {
	var BANNER_COUNT = 7;
	$$('.banner')[0].down().down().src = "images/banner" + Math.floor(Math.random()*BANNER_COUNT) + ".jpg";
}

Event.observe(window, 'load', leftnav_init);
Event.observe(window, 'load', select_banner);