(function($){
	
	$.fn.menuHover = function(options){
		this.rolled_out=false;
		this.menu_timeout=false;
		this.settings = $.extend({}, $.fn.menuHover.defaults, options);
		$(this.settings.content_selector,this).height(this.settings.menu_height-get_mp_height($(this.settings.content_selector,this)));


		if(this.settings.addBorder){

		}
		
		var self=this;
		// if($.browser.msie){
		// 	//move the ie menus to the bottom so they will show above the rest of the content when clicked
		// 	var h=$(this).parent();
		// 	$(this).parent().remove();
		// 	$('div#wrapper').append(h);
		// 	$(this).parent().css('display','block');
		// 		
		// }
		$(this.settings.trigger_selector,this).bind('click',
			function(){
				if(self.rolled_out){
					$.fn.menuHover.roll_up(self);
				}
				else{
					$.fn.menuHover.roll_down(self);
				}
			}
		);
	};
	$.fn.menuHover.roll_up = function(curr){
		$.fn.menuHover.unbind_leave(curr);
		curr.rolled_out=false;
		$(curr.settings.wrapper_selector,curr).animate({height:0},function(){
			if(curr.settings.addBorder){
				$(curr.settings.wrapper_selector,curr).css('border','none');
			}
			});
	};
	$.fn.menuHover.roll_down = function(curr){
		if(curr.settings.addBorder){
			$(curr.settings.wrapper_selector,curr).css('border',curr.settings.addBorder);
		}
		$(curr.settings.wrapper_selector,curr).animate({height:curr.settings.menu_height},function(){
			curr.rolled_out=true;
			$.fn.menuHover.bind_leave(curr);
		});
	};
	$.fn.menuHover.unbind_leave = function(curr){
		curr.rolled_out=false;
		curr.menu_timeout=false;
		$(curr.settings.hover_area_selector,curr).unbind('mouseenter');
		$(curr.settings.hover_area_selector,curr).unbind('mouseleave');
		$('body').unbind('click');

	};
	$.fn.menuHover._bind_mouse_leave = function(curr){
		if(curr.rolled_out){
			if(curr.menu_timeout){
				window.clearTimeout(curr.menu_timeout);
			}
		}
		curr.menu_timeout=window.setTimeout(function(){
			$(curr.settings.wrapper_selector,curr).animate(
				{height:0},
					function(){
						if(curr.settings.addBorder){
							$(curr.settings.wrapper_selector,curr).css('border','none');
						}
						$.fn.menuHover.unbind_leave(curr);
					});
				},
			curr.settings.mouseout_length);
	};
	$.fn.menuHover._bind_mouse_enter = function(curr){
		if(curr.rolled_out){
			if(curr.menu_timeout){
				window.clearTimeout(curr.menu_timeout);
			}
		}
	};
	$.fn.menuHover.bind_leave = function(curr){
		$(curr.settings.hover_area_selector,curr).bind('mouseleave',function(){$.fn.menuHover._bind_mouse_leave(curr);});
		$(curr.settings.hover_area_selector,curr).bind('mouseenter',function(){$.fn.menuHover._bind_mouse_enter(curr);});
		$('body').bind('click',function(){$.fn.menuHover.roll_up(curr)});
	};
	$.fn.menuHover.defaults = {
		mouseout_length:2000,
		hover_area_selector:'.dropdown_hover_area',
		wrapper_selector:'.dropdown_wrapper',
		content_selector:'.dropdown_content',
		trigger_selector:'.dropdown_trigger',
		menu_height:250
		
	};
})(jQuery);