/* 
REV 11/18/10

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:

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>

*/

function initMenus() {
	var animationSpeed = 500; // number of milliseconds for animation speed

	$('ul.menu ul').hide();
	$.each($('ul.menu'), function(){
		$('#' + this.id + '.expandfirst ul:first').show();
	});
	$('ul.menu li a').hoverIntent(
		{
			sensitivity: 1, // number = sensitivity threshold (must be 1 or higher)    
			interval: 300, // number = milliseconds for onMouseOver polling interval    
			over: function() {
				var checkElement = $(this).next();
				var parent = this.parentNode.parentNode.id;
	
				if((checkElement.is('ul')) && (checkElement.is(':visible'))) {
					if($('#' + parent).hasClass('collapsible')) {
						$('#' + parent + ' ul:visible').slideUp(animationSpeed);
					}
					return false;
				}
				if((checkElement.is('ul')) && (!checkElement.is(':visible'))) {
					$('#' + parent + ' ul:visible').slideUp(animationSpeed);
					checkElement.slideDown(animationSpeed);
					return false;
				}
			},
			timeout: 500, // number = milliseconds delay before onMouseOut    
			out: function() {}
		}
	);
}
$(document).ready(function() {initMenus();});
