/********************************************************************************\ 
	Based on defaults/jquery.menu.js
\********************************************************************************/
$.fn.gwMenu = function(options) {
	options = $.extend(options || {});
	
	this.each(function() {
		var root = this, zIndex = 1000;
	
		function getSubnav(ele) {
			if (ele.nodeName.toLowerCase() == 'li') {
				var subnav = $('> ul', ele);
				return subnav.length ? subnav[0] : null;
			} else {
				return ele;
			}
		}
		
		function getActuator(ele) {
			if (ele.nodeName.toLowerCase() == 'ul') {
				return $(ele).parents('li')[0];
			} else {
				return ele;
			}
		}
		
		function hide() {
			var subnav = getSubnav(this);
			if (!subnav) return;
			$.data(subnav, 'cancelHide', false);
			if (!$.data(subnav, 'cancelHide')) {
				$(subnav).hide();
			}
		}
	
		function show() {
			var subnav = getSubnav(this);
			if (!subnav) return;
			$.data(subnav, 'cancelHide', true);
			$(subnav).css({zIndex: zIndex++}).show();
			if (this.nodeName.toLowerCase() == 'ul') {
				var li = getActuator(this);
				$(li).addClass('hover');
				$('> a', li).addClass('hover');
			}
		}
		
		//had to edit this to ignore flat dropdowns
		$('li:not([class]), ul:not([class])', this).hover(show, hide);
		$('li', this).hover(
			function() { $(this).addClass('hover'); $('> a', this).addClass('hover'); },
			function() { $(this).removeClass('hover'); $('> a', this).removeClass('hover'); }
		);
		
		//move nav ball to current page
		/*
		var loc = new String(window.location);
		$('>li', this).each(function(i){
			//if we're at a subpage of the link
			if(loc.indexOf($('>a', this)[0].href)==0){
				//left = link's left corner + half link's width - half ball's width
				var left = $(this).position().left + $(this).width()/2 - 9;
				// move nav ball
				$('#gw-nav .wrapper').css('background-position', left + 'px 29px');
				// kill each loop
				//return false;
			}
			//test
			$(this).css('background', '#f3f');
			return false;
		});
		*/
		
		
		
	});
};