/* 
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

Optional extra classnames:

noaccordion : no accordion functionality - simple slide menu
collapsible : menu works like an accordion but can be fully collapsed
expandcurrent : class = current_page_item: add to submenu ul to expand by default (adapted by oultine4.ch)

Copyright 2008 by Marco van Hylckama Vlieg

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

Free for non-commercial use


For anyone wanting to have the menus open on hover instead of click, just change 
.click to .hover (obviously) AND add a null function() {} after the first fucntion 
(with a comma at the end of the prev function), as jqueryÕs .hover event expects (over, out), 
and without the ÔoutÕ it will create an error.

Not sure if the code will make it, but as well as changing .click to .hover, change the last few lines FROM: 

}
);
}
$(document).ready(function() {initMenus();});

...TO: 

}, 
function() {} 

);
} 
$(document).ready(function() {initMenus();});



*/

function initMenus() {
	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		// adapted by outline4.ch
		$('#' + this.id + '.expandcurrent ul.current_page_item').show();
	});
	$('ul.menu 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('ul')) && (checkElement.is(':visible'))) {
				if($('#' + parent).hasClass('collapsible')) {
					$('#' + parent + ' ul:visible').slideUp('normal');
				}
				return false;
			}
			if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
				$('#' + parent + ' ul:visible').slideUp('normal');
				checkElement.slideDown('normal');
				return false;
			}
		}
	);
}
$(document).ready(function() {initMenus();});
