(function(f){var e=0;function d(n){var o=this,p;o.items=[];o.settings=n=f.extend({menu_class:"menu",menu_item_class:"menuitem",item_class:"item",separator_class:"separator",submenu_item_class:"submenu",active_class:"active"},n);o.id=n.id;if(n.setup){n.setup.call(o,o)}function k(g){if(g.target.nodeName!=="A"||!f(g.target).parents("div."+n.menu_class).length){o.hide()}}function a(h){var g;if(h.target.nodeName==="A"){g=o.find(h.target.rel);if(!g.show&&!g.disabled){if(g.onclick){g.onclick.call(g.scope||this,h,g)}if(n.onClick){n.onClick(h,g)}g=o;do{g.hide()}while(g=g.parentMenu)}h.preventDefault();return false}}function b(j){var t,h,i,g,l;if(j.target.nodeName==="A"){if(o.lastMenu){o.lastMenu.hide()}if(g=o.find(j.target.rel)){if(g.show){l=f(j.target.parentNode);i=l.offset();t=i.left+l.width();h=i.top;l.addClass(g.settings.active_class);o.lastMenu=g;g.show(t,h)}}}}function m(i,h,g){i=document.createElement(i);if(h){f(i).attr(h)}if(g){f(i).html(g)}return i}function c(){return"jquery_mc_"+e++}f.extend(this,{createMenu:function(g){return new d(g)},find:function(g){var h;for(h=0;h<o.items.length;h++){if(o.items[h].id===g){return o.items[h]}}return null},clear:function(){o.hide();o.items=[];f("#"+o.id).remove();o.rendered=0},render:function(g){if(!g.id){g.id=o.id=c()}else{o.id="jquery_mc_"+g.id}if(n.onInit){n.onInit(o)}},show:function(s,h){var l,i,g,j=o.settings;if(o.visible){o.hide()}f(o).trigger("DropMenu:beforeshow",[o]);f().trigger("DropMenu:beforeshow",[o]);if(!o.rendered){l=m("div",{id:o.id,"class":j.menu_class});f.each(o.items,function(z,A){var y,r,q="",v;if(A.constructor==d){y=A.settings.title;q=" "+j.submenu_item_class;if(A.settings["class"]){q+=" "+A.settings["class"]}}else{y=A.title;if(this["class"]){q=" "+A["class"]}}if(A.disabled||A.settings&&A.settings.disabled){q+=" disabled"}i=m("div",{id:o.id+"_"+A.id,"class":j.menu_item_class+q});v=m("a",{rel:A.id,href:"#"},y);f(i).append(v);f(l).append(i)});f(document.body).append(l);o.rendered=1}f().mouseup(k);g=f("#"+o.id);g.mouseover(b).show().css({left:-5000,top:-5000});if(j.halign=="right"){s-=g.width()}if(j.valign=="bottom"){h-=g.height()}if(j.constrain){s=s<0?0:s;h=h<0?0:h;s=s+g.width()>f.winWidth()?f.winWidth()-g.width():s;h=h+g.height()>f.winHeight()?f.winHeight()-g.height():h}g.css({left:s,top:h}).click(a);o.visible=1;f(o).trigger("DropMenu:show");f().trigger("DropMenu:show",[o]);return false},hide:function(){if(!o.visible){return false}f("a[@rel="+o.id+"]").parent().removeClass("active");f().unbind("mouseup",k);f("#"+o.id).unbind("mouseover",b).hide();f("#"+o.id).unbind("click",a);o.visible=0;f.each(o.items,function(){if(this.hide){this.hide()}});f(o).trigger("DropMenu:hide");f().trigger("DropMenu:hide",[o]);return false},add:function(g){g.id=g.id||c();o.items.push(g);return g},addSeparator:function(){return o.add({"class":n.separator_class,title:"separator"})},addMenu:function(g){if(!g.onClick){g.onClick=n.onClick}g=new d(g);g.parentMenu=o;return o.add(g)}})}jQuery.mcDropMenu=d;jQuery.fn.mcContextMenu=function(a){this.each(function(){var b=new f.mcDropMenu(a);b.render(this);f(this).bind("contextmenu",function(c){return b.show(c.clientX,c.clientY)})})}})(jQuery);