/* 
Simple JQuery menu.
HTML structure to use:

Notes: 

1: each menu MUST have an ID set. It doesn't matter what this ID is as long as it's there.
2: each menu MUST have a class 'menu' set. If the menu doesn't have this, the JS won't make it dynamic
3: this version adapted slightly for Mindspace from the original, replacing the ul and li elements with spans

Optional extra classnames:

noaccordion : no accordion functionality
collapsible : menu works like an accordion but can be fully collapsed
expandfirst : first menu item expanded at page load

<ul id="accordion1" class="accordion [optional class] [optional class]">
<span>
	<p>Stuff here</p>
</span>
</ul>

Copyright 2008 by Marco van Hylckama Vlieg

web: http://www.i-marco.nl/weblog/
email: marco@i-marco.nl

Free for non-commercial use
*/

function initMenus() {
	$('ul.accordion div').hide();
	$.each($('ul.accordion'), function(){
		$('#' + this.id + '.expandfirst div:first').show();
	});
	$('ul.accordion li a').click(
		function() {
			var checkElement = $(this).next();
			var parent = this.parentNode.parentNode.id;

			if($('#' + parent).hasClass('noaccordion')) {
				$(this).next().slideToggle('normal');
				return false;
			}
			if((checkElement.is('div')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' div:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('div')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' div:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function() {initMenus();});
