// JavaScript Document

(function($) {
    $.fn.extend({
        menu: function(options) {
			
			var defaults = {
    			  subClass: 'sub',
				  subWidth: 100,
				  subHeight: 20,
				  subBackColor: '#FFFFFF',
				  subBorderStyle: 'none',
				  linkPadding: '0px',
				  topPosition: 0,
				  leftPosition: 0,
				  showAction: 'show',
				  speed: 500
			};

			
			var options = $.extend(defaults, options);
			
			return this.each(function() { 
				var obj = $(this);
				var op = options;
				var parentHeight = obj.children('li').height();
				
				
				obj.children('li').css({'position': 'relative', 'z-index': '100'});
				
				obj.find('.' + op.subClass + ' li').css({
						'width': '100%',
						'height': op.subHeight,
						'clear': 'both',
						'background-color': op.subBackColor
					});
					
				obj.find('.' + op.subClass).css({
						'border': op.subBorderStyle,
						'position': 'absolute',
						'z-index': '100',
						'top': op.topPosition + 'px',
						'left': op.leftPosition + 'px'
					});
					
				obj.find('.' + op.subClass + ' li a').css({
						'display': 'block',
						'width': '100%',
						'padding': op.linkPadding
					});
					
				obj.find('.' + op.subClass).hide();
				
				obj.children('li').children('a').mouseover(function(event){
					obj.showSub($(this), op.subClass, op.showAction, op.speed);	
				});
				
				obj.find('.' + op.subClass).mouseleave(function(event){
					obj.hideSubs(op.subClass);			
				});
				
				obj.mouseleave(function(event){
					obj.hideSubs(op.subClass);			
				});
			})
        }
    });
	
	$.fn.showSub = function(target, triggerClass, showAction, speed)
	{
		$('.' + triggerClass).stop(true,true);
		$('.' + triggerClass).hide();
		if ($(target).next().attr('class') == triggerClass) {
			if (showAction == 'show' || showAction == '') {
				$(target).next().show(speed);				
			} else {
				$(target).next().slideDown(speed);
			}
		}
	}
	
	$.fn.hideSubs = function(subClass)
	{
		$('.' + subClass).stop(true, true);
		$('.' + subClass).hide();
	}
	
})(jQuery);



