/* 
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
collapsible : menu works like an accordion but can be fully collapsed
expandfirst : first menu item expanded at page load

<ul id="menu1" class="menu [optional class] [optional class]">
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
<li><a href="#">Sub menu heading</a>
<ul>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
<li><a href="http://site.com/">Link</a></li>
...
...
</ul>
...
...
</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.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.ExpandULID_0 ul:eq(0)').show();
		$('#' + this.id + '.ExpandULID_1 ul:eq(1)').show();
		$('#' + this.id + '.ExpandULID_2 ul:eq(2)').show();
		$('#' + this.id + '.ExpandULID_3 ul:eq(3)').show();
		$('#' + this.id + '.ExpandULID_4 ul:eq(4)').show();
		$('#' + this.id + '.ExpandULID_5 ul:eq(5)').show();
		$('#' + this.id + '.ExpandULID_6 ul:eq(6)').show();
		$('#' + this.id + '.ExpandULID_7 ul:eq(7)').show();
		$('#' + this.id + '.ExpandULID_8 ul:eq(8)').show();
		$('#' + this.id + '.ExpandULID_9 ul:eq(9)').show();
		$('#' + this.id + '.ExpandULID_10 ul:eq(10)').show();
		$('#' + this.id + '.ExpandULID_11 ul:eq(11)').show();
		$('#' + this.id + '.ExpandULID_12 ul:eq(12)').show();
		$('#' + this.id + '.ExpandULID_13 ul:eq(13)').show();
		$('#' + this.id + '.ExpandULID_14 ul:eq(14)').show();
		$('#' + this.id + '.ExpandULID_15 ul:eq(15)').show();
		$('#' + this.id + '.ExpandULID_16 ul:eq(16)').show();
		$('#' + this.id + '.ExpandULID_17 ul:eq(17)').show();
		$('#' + this.id + '.ExpandULID_18 ul:eq(18)').show();
		$('#' + this.id + '.ExpandULID_19 ul:eq(19)').show();
		$('#' + this.id + '.ExpandULID_20 ul:eq(20)').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();});