(function($) {
	$.fn.pulldown = function(config){
		var cfg = {
			hoverClass		: 'active',			// Css class of the li that is being hovered
			mouseOut		: '200',			// Number of Miliseconds before menu closes after mouseout
			slideSpeed		: 250
		}
		var config = jQuery.extend(cfg, config);
		
		return this.each(function(){		
			var $this = $(this);
			var base_back = $this.css('backgroundImage');
			$this.css({
				'background-image' : 'none'
			});
			var base_height = $this.height() + 7;
			
			var pullMenuDown = function(){
				$("body").find("select").hide();
				slideMenuBase($(this), $(this).find("ul").height());
				$(this).find("ul").slideDown(config.slideSpeed);
			};
			
			var pullMenuUp = function() {
				$(this).children("a").removeClass("active");
				$(this).find("ul").hide();
			};
			
			var slideMenuBase = function(el, height){
				$(el).children("a").addClass("active");
				$(el).parent().children("li").find("ul").hide();
				$(el).parent().css('backgroundImage', base_back);
				
				var new_height = height + 63 + 'px';
				
				if (!height)
					new_height = '37px';
				
				$this.animate({
					height: new_height
				},
				config.slideSpeed);
			};
			
			var mousein = function(){
				return;
			};
			
			var mouseout = function(){
				$(this).animate({
					height: base_height +'px'
				},
				config.slideSpeed,
				function(){
					$(this).css({
						'background-image' : 'none'
					});
					$("body").find("select").show();
				});
				$(this).find("ul").slideUp(config.slideSpeed);
			};
		
		
			//alert($this.children("li:has(ul)").children("ul").html());
			$this.children("li")['hoverIntent'](pullMenuDown,pullMenuUp);
			$(this)['hoverIntent'](mousein,mouseout);
		});
		
	};

})(jQuery);
