(function($) {
	
	$.fn.dropdownMenu = function(params) {
		
		var settings = $.extend({
			
			
			
		}, params);
		
		$(this).each(function() {
			
			$("a[href='#']").click(function(e) { if(e.stopPropagation) e.stopPropagation(); if(e.preventDefault) e.preventDefault(); return false; });
			/* var curSel = null;
			
			$(this).children("li").mouseenter(function() {
				
				if(curSel != null) curSel.trigger("mouseleave");
				
				var subnav = $("ul.subnav", $(this));
				if(subnav.length == 0) return;
				
				$(this).addClass("hover");
				var h = subnav.show(0).height();
				var w = subnav.width() < $(this).width() ? $(this).width() + "px" : "";
				if(h == 0) h = "toggle"; else h = h + "px";
				subnav.hide(0).css({ height: "0px", opacity: "0", width: w }).animate({ height: h, opacity: 1.0 }, { duration: 300, easing: "linear", queue: false });
				
				curSel = subnav;
				
			}).mouseleave(function() {
				
				var subnav = $("ul.subnav", $(this));
				if(subnav.length == 0) return;
				
				var _this = this;
				subnav.animate({ height: "0px", opacity: 0 }, { 
					duration: 200, 
					easing: "linear", 
					queue: false, 
					complete: function() {
						$(this).hide(0).css({ height: "auto" });
						$(_this).removeClass("hover");
					}
				});
				curSel = null;
			}); */
			
			$("li", $(this)).mouseenter(function() {
				var subgroup = $(this).children("ul");
				if(subgroup && subgroup.length > 0) {
					subgroup.clearQueue();
					if(subgroup.hasClass("subnav")) {
						$(this).siblings().each(function() {
							var sibsubs = $(this).children("ul").filter(function(){ return $(this).css("display") != "none" ? true : false });
							var w = subgroup.data("oWidth") != undefined ? subgroup.data("oWidth") : $(this).width();
							$(sibsubs).each(function() {
								$("ul", sibsubs).animate({width: "0px"}, { duration: "fast", complete: function(){
									$(this).css({ width: w+"px", display: "none" });
								} });
								
								var h = $(sibsubs).height();
								$(sibsubs).animate({ height: "0px" }, { duration: "fast", complete: function() {
									$(this).hide(0).css({ height: "auto" });
								}});
							});
						});
						var h = subgroup.height();
						subgroup.css({ height: "0px" }).show(0).animate({ height: h + "px" }, { duration: "fast", complete: function() {
							
						}});
					} else {
						/* $(this).children("a").addClass("children"); */
						var w = subgroup.data("oWidth") != undefined ? subgroup.data("oWidth") : subgroup.width();
						if(subgroup.data("oWidth") == undefined) subgroup.data("oWidth", w);
						subgroup.css({
							width: "0px",
							display: "block",
							"margin-left": ($(this).position().left+$(this).outerWidth(true)+1)+"px"
						}).animate({width: w+"px"}, { duration: "fast", complete: function(){ $(this).width(w);}});
					}
					$(this).addClass("hover");
				}
			}).mouseleave(function() {
				var subgroup = $(this).children("ul");
				if(subgroup && subgroup.length > 0) {
					var _this = this;
					if(subgroup.hasClass("subnav")) {
						subgroup.delay(100).animate({ height: "0px" }, { duration: "fast", complete: function() {
							$(this).hide(0).css({ height: "auto" });
							$(_this).removeClass("hover");
						}});
					} else {
						/* $(this).children("a").removeClass("children"); */
						var w = subgroup.data("oWidth") != undefined ? subgroup.data("oWidth") : $(this).width();
						subgroup.delay(100).animate({width: "0px"}, { duration: "fast", complete: function(){ 
							$(this).css({
								width: w+"px",
								display: "none"
							});
							$(_this).removeClass("hover");
						}});
					}
				}
			});
			
			$("li ul li a").mouseenter(function() {
				
			}).mouseleave(function() {
				
			});
			
		});
		
	};
	
})(jQuery);
