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