/** jQuery jMenu plugin
	* Written by J. Wodzynski/Entireweb
	* License: same as jQuery, see: http://jquery.com/license
	*/
(function($) {
	$.fn.jmenu = function(options) {
	// build main options before element iteration
	var opts = $.extend({}, $.fn.jmenu.defaults, options);
	// iterate and reformat each matched element
		return this.each(function() {
			$headlink = $('li.headlink', this);
			
			$innerlink =  $('li.headlink ul li', this);
			
			// add/remove .over class for .hover and show/hide the dropdown inside (if any)
			$headlink.hover(
				function() {
					$('a', this).addClass('over');
					$('ul', this).css('display', 'block'); 
				},
				function() { 
					$('a', this).removeClass('over');
					$('ul', this).css('display', 'none'); 
				}
			);
			
			// add .active class if document.location matches the current href
			$headlink.children('a').each(function() {	
				$t = $(this);
				if($t.attr('href') == document.location.pathname)
					$t.addClass('active');
			});
			
			// add/remove .over class for the dropdown items and bind the click event for the whole <li>
			$innerlink
				.hover(
					function() {
						$(this).addClass('over');
					},
					function() {
						$(this).removeClass('over');
					}
				)
				.bind('click', function(e) {
					document.location = $(this).children('a').attr('href');
				})
				//loop through links and set .active on the parent <li> if it matches the pathname
				.children('a').each(function() {
					$t = $(this);
					if($t.attr('href') == document.location.pathname)
						$t.parent().addClass('active');
				});

			// build element specific options
			//var o = $.meta ? $.extend({}, opts, $this.data()) : opts;

			// update element styles
			//$this.css({
			//	backgroundColor: o.background,
			//	color: o.foreground
			//});
			
			//var markup = $this.html();
			
			// call our format function
			//markup = $.fn.jmenu.format(markup);
			//$this.html(markup);
		});
	};
	//
	// private function for debugging
	//
	function debug(a, b) {
		if (window.console && window.console.log)
			window.console.log(a, b);
	};
	//
	// define and expose our format function
	//
	//$.fn.jmenu.format = function(txt) {
	//	return '<strong>' + txt + '</strong>';
	//};
	//
	// plugin defaults
	//
	//$.fn.jmenu.defaults = {
	//	foreground: 'red',
	//	background: 'yellow'
	//};
})(jQuery);