",{href:"#"+o.val(),rel:o.val()}).text(o.text()).bind("click.sb",function(t){t&&t.preventDefault&&t.preventDefault();{var a=r,i=e(this);a.attr("id").split("_")[1]}b._changeSelectbox(s,i.attr("rel"),i.text()),b._closeSelectbox(s)}).bind("mouseover.sb",function(){var s=e(this);s.parent().siblings().find("a").removeClass(g.settings.classFocus),s.addClass(g.settings.classFocus)}).bind("mouseout.sb",function(){e(this).removeClass(g.settings.classFocus)}),t&&l.addClass(g.settings.classSub),o.is(":selected")&&l.addClass(g.settings.classFocus),l.appendTo(c)),c.appendTo(u)})}if(this._getInst(s))return i;var c,d,r,u,p=e(s),b=this,g=b._newInst(p),f=i,h=(p.find("optgroup"),p.find("option")),_=h.length;p.attr("sb",g.uid),e.extend(g.settings,b._defaults,t),b._state[g.uid]=i,p.hide(),c=e("",{id:"sbHolder_"+g.uid,"class":g.settings.classHolder,tabindex:p.attr("tabindex")}),d=e("
",{id:"sbSelector_"+g.uid,href:"#","class":g.settings.classSelector,click:function(t){t.preventDefault(),l.apply(e(this),[]);var a=e(this).attr("id").split("_")[1];b._state[a]?b._closeSelectbox(s):b._openSelectbox(s)}}),r=e("",{id:"sbToggle_"+g.uid,href:"#","class":g.settings.classToggle,click:function(t){t.preventDefault(),l.apply(e(this),[]);var a=e(this).attr("id").split("_")[1];b._state[a]?b._closeSelectbox(s):b._openSelectbox(s)}}),r.appendTo(c),u=e("",{id:"sbOptions_"+g.uid,"class":g.settings.classOptions,css:{display:"none"}}),p.children().each(function(){var s,t=e(this),a={};t.is("option")?o(t):t.is("optgroup")&&(s=e("- "),e("",{text:t.attr("label")}).addClass(g.settings.classGroup).appendTo(s),s.appendTo(u),t.is(":disabled")&&(a.disabled=!0),a.sub=!0,o(t.find("option"),a))}),f||d.text(h.first().text()),e.data(s,a,g),c.data("uid",g.uid).bind("keydown.sb",function(s){var t=s.charCode?s.charCode:s.keyCode?s.keyCode:0,i=e(this),n=i.data("uid"),l=i.siblings("select[sb='"+n+"']").data(a),o=i.siblings(["select[sb='",n,"']"].join("")).get(0),c=i.find("ul").find("a."+l.settings.classFocus);switch(t){case 37:case 38:if(c.length>0){var d;e("a",i).removeClass(l.settings.classFocus),d=c.parent().prevAll("li:has(a)").eq(0).find("a"),d.length>0&&(d.addClass(l.settings.classFocus).focus(),e("#sbSelector_"+n).text(d.text()))}break;case 39:case 40:var d;e("a",i).removeClass(l.settings.classFocus),d=c.length>0?c.parent().nextAll("li:has(a)").eq(0).find("a"):i.find("ul").find("a").eq(0),d.length>0&&(d.addClass(l.settings.classFocus).focus(),e("#sbSelector_"+n).text(d.text()));break;case 13:c.length>0&&b._changeSelectbox(o,c.attr("rel"),c.text()),b._closeSelectbox(o);break;case 9:if(o){var l=b._getInst(o);l&&(c.length>0&&b._changeSelectbox(o,c.attr("rel"),c.text()),b._closeSelectbox(o))}var r=parseInt(i.attr("tabindex"),10);s.shiftKey?r--:r++,e("*[tabindex='"+r+"']").focus();break;case 27:b._closeSelectbox(o)}return s.stopPropagation(),!1}).delegate("a","mouseover",function(){e(this).addClass(g.settings.classFocus)}).delegate("a","mouseout",function(){e(this).removeClass(g.settings.classFocus)}),d.appendTo(c),u.appendTo(c),c.insertBefore(p),e("html").on("mousedown",function(s){s.stopPropagation(),e("select").selectbox("close")}),e([".",g.settings.classHolder,", .",g.settings.classSelector].join("")).mousedown(function(e){e.stopPropagation()})},_detachSelectbox:function(s){var t=this._getInst(s);return t?(e("#sbHolder_"+t.uid).remove(),e.data(s,a,null),void e(s).show()):i},_changeSelectbox:function(s,t,a){var i,l=this._getInst(s);l&&(i=this._get(l,"onChange"),e("#sbSelector_"+l.uid).text(a)),t=t.replace(/\'/g,"\\'"),e(s).find("option[value='"+t+"']").prop("selected",n),l&&i?i.apply(l.input?l.input[0]:null,[t,l]):l&&l.input&&l.input.trigger("change")},_enableSelectbox:function(s){var t=this._getInst(s);return t&&t.isDisabled?(e("#sbHolder_"+t.uid).removeClass(t.settings.classHolderDisabled),t.isDisabled=i,void e.data(s,a,t)):i},_disableSelectbox:function(s){var t=this._getInst(s);return!t||t.isDisabled?i:(e("#sbHolder_"+t.uid).addClass(t.settings.classHolderDisabled),t.isDisabled=n,void e.data(s,a,t))},_optionSelectbox:function(s,t,n){var l=this._getInst(s);return l?(l[t]=n,void e.data(s,a,l)):i},_openSelectbox:function(s){var t=this._getInst(s);if(t&&!t.isOpen&&!t.isDisabled){var i=e("#sbOptions_"+t.uid),l=parseInt(e(window).height(),10),o=e("#sbHolder_"+t.uid).offset(),c=e(window).scrollTop(),d=i.prev().outerHeight(),r=l-(o.top-c)-d/2,u=this._get(t,"onOpen");200>r?(r=o.top-c-(e("#stuck").outerHeight()+10),i.css({top:"auto",bottom:d+"px",maxHeight:r+"px"})):i.css({bottom:"auto",top:d+"px",maxHeight:r-d+"px"}),"fade"===t.settings.effect?i.fadeIn(t.settings.speed):i.slideDown(t.settings.speed),e("#sbToggle_"+t.uid).addClass(t.settings.classToggleOpen),this._state[t.uid]=n,t.isOpen=n,u&&u.apply(t.input?t.input[0]:null,[t]),e.data(s,a,t)}},_closeSelectbox:function(s){var t=this._getInst(s);if(t&&t.isOpen){var n=this._get(t,"onClose");"fade"===t.settings.effect?e("#sbOptions_"+t.uid).fadeOut(t.settings.speed):e("#sbOptions_"+t.uid).slideUp(t.settings.speed),e("#sbToggle_"+t.uid).removeClass(t.settings.classToggleOpen),this._state[t.uid]=i,t.isOpen=i,n&&n.apply(t.input?t.input[0]:null,[t]),e.data(s,a,t)}},_newInst:function(e){var s=e[0].id.replace(/([^A-Za-z0-9_-])/g,"\\\\$1");return{id:s,input:e,uid:Math.floor(99999999*Math.random()),isOpen:i,isDisabled:i,settings:{}}},_getInst:function(s){try{return e.data(s,a)}catch(t){throw"Missing instance data for this selectbox"}},_get:function(e,t){return e.settings[t]!==s?e.settings[t]:this._defaults[t]}}),e.fn.selectbox=function(s){var t=Array.prototype.slice.call(arguments,1);return"string"==typeof s&&"isDisabled"==s?e.selectbox["_"+s+"Selectbox"].apply(e.selectbox,[this[0]].concat(t)):"option"==s&&2==arguments.length&&"string"==typeof arguments[1]?e.selectbox["_"+s+"Selectbox"].apply(e.selectbox,[this[0]].concat(t)):this.each(function(){"string"==typeof s?e.selectbox["_"+s+"Selectbox"].apply(e.selectbox,[this].concat(t)):e.selectbox._attachSelectbox(this,s)})},e.selectbox=new t,e.selectbox.version="0.2"}(jQuery);