(function(d){function f(a){var b=d.data(a,"menubutton").options;var c=d(a);c.removeClass("m-btn-active m-btn-plain-active").addClass("m-btn");c.linkbutton(d.extend({},b,{text:b.text+'<span class="m-btn-downarrow">&nbsp;</span>'}));if(b.menu){d(b.menu).menu({onShow:function(){c.addClass((b.plain==true)?"m-btn-plain-active":"m-btn-active")},onHide:function(){c.removeClass((b.plain==true)?"m-btn-plain-active":"m-btn-active")}})}e(a,b.disabled)}function e(b,j){var k=d.data(b,"menubutton").options;k.disabled=j;var l=d(b);if(j){l.linkbutton("disable");l.unbind(".menubutton")}else{l.linkbutton("enable");l.unbind(".menubutton");l.bind("click.menubutton",function(){a();return false});var c=null;l.bind("mouseenter.menubutton",function(){c=setTimeout(function(){a()},k.duration);return false}).bind("mouseleave.menubutton",function(){if(c){clearTimeout(c)}})}function a(){if(!k.menu){return}var g=l.offset().left;if(g+d(k.menu).outerWidth()+5>d(window).width()){g=d(window).width()-d(k.menu).outerWidth()-5}d("body>div.menu-top").menu("hide");d(k.menu).menu("show",{left:g,top:l.offset().top+l.outerHeight()});l.blur()}}d.fn.menubutton=function(a,b){if(typeof a=="string"){return d.fn.menubutton.methods[a](this,b)}a=a||{};return this.each(function(){var c=d.data(this,"menubutton");if(c){d.extend(c.options,a)}else{d.data(this,"menubutton",{options:d.extend({},d.fn.menubutton.defaults,d.fn.menubutton.parseOptions(this),a)});d(this).removeAttr("disabled")}f(this)})};d.fn.menubutton.methods={options:function(a){return d.data(a[0],"menubutton").options},enable:function(a){return a.each(function(){e(this,false)})},disable:function(a){return a.each(function(){e(this,true)})},destroy:function(a){return a.each(function(){var b=d(this).menubutton("options");if(b.menu){d(b.menu).menu("destroy")}d(this).remove()})}};d.fn.menubutton.parseOptions=function(a){var b=d(a);return d.extend({},d.fn.linkbutton.parseOptions(a),{menu:b.attr("menu"),duration:b.attr("duration")})};d.fn.menubutton.defaults=d.extend({},d.fn.linkbutton.defaults,{plain:true,menu:null,duration:100})})(jQuery);