(function(jQuery) {	
	jQuery.fn.extend({
		dropdownmenu : function (initOptions) {
			var options, trackingId, hideTimer, showTimer;
			options = jQuery.extend(true, {
				duration: 300,
				animationIn: 'fade',
				animationOut: 'fade'
			}, initOptions);
			
			var parent = jQuery(this);			
			parent.removeClass('noJS');
			var submenuLinks = jQuery("> li", parent);
			jQuery("ul", submenuLinks).css({'display': 'none'});				
			jQuery("ul", submenuLinks).each(function () {
				var $this = jQuery(this);
				var tempTrackingId = $this.prev().attr('id') || $this.parent().attr('id');				
				$this.attr('trackingid', tempTrackingId);
			});
				
			
			return this.each(function(){
				jQuery(submenuLinks).hover(
					function(){
						var $this = jQuery("> ul", this);
						if(trackingId == $this.attr('trackingid')){		
					    	clearTimeout(showTimer);
					    	clearTimeout(hideTimer);
					    }else{
					    	trackingId = $this.attr('trackingid');
					    }
						showTimer = setTimeout(function(){
							if (typeof(options.animationIn) === 'function') {
							options.animationIn($this);
							} else {
								switch(options.animationIn) {
									case "fade":
										$this.stop(true, true).fadeIn(options.duration);		
										break;
									case "slide":									
										$this.stop(true, true).slideDown(options.duration);
										break;
									default:										
										$this.stop(true, true).show();											
								}
							}						
						}, 100);											
					},
					function(){
						var $this = jQuery("> ul", this);
						if(trackingId == $this.attr('trackingid')){
					    	clearTimeout(showTimer);
					    }else{
					    	trackingId = $this.attr('trackingid');
					    }
					    hideTimer = setTimeout(function(){
					    	if (typeof(options.animationOut) === 'function') {
								options.animationOut($this);
							} else {
								switch(options.animationOut) {
									case "fade":									
										$this.stop(true, true).fadeOut(options.duration);														
										break;
									case "slide":
										$this.stop(true, true).slideUp(options.duration);
										break;
									default:									
										$this.stop(true, true).hide();
								}
							}
					    }, 200);					    						
					}
				);
			})
		}
	})	
})(jQuery);
