(function($) {

	$.mp = $.mp || {};
	
	$.mp.subs=[];

    // menu initialization
	$.fn.dropNav = function(options) {
		options=$.extend({dropButtonClass:'dropButton',dropButtonText:'&raquo;'},options);
		$('li ul',this).each(function(){new $.mp.initDropNav(this)});
	};
	
	$.mp.initDropNav=function(el,options){
		$.mp.subs.push(el);
		$(el).hide();
		$.mp.createButton(el,options);
	}
	
	$.mp.createButton=function(el,options){
		$(el).addClass('dropper').before(
			$(document.createElement('a')).html('&raquo;').attr('href','#').addClass('drop_btn').triggerAttachBehaviors(el)
			);

	}
	
	$.mp.toggle=function(el){
			li=$(el.parentNode);
			if (!li.hasClass('dropped')) {
				$.each($.mp.subs,
						function(){
							$(this.parentNode).removeClass('dropped');
							$(this).hide();
						}
					)
			};
			$(el.parentNode).toggleClass('dropped');
			$(el).toggle();
			$.mp.droppedMenu=$(el);
	}
	
	$.fn.triggerAttachBehaviors=function(el){
		// console.debug(el);
		this.click(function(){$.mp.toggle(el)});
		this.hover(function(){$(el.parentNode).addClass('hover')},function(){$(el.parentNode).removeClass('hover')})
		return this;
	}
	
})(jQuery);