!function(a){a.widget("custom.combobox",{_create:function(){this.wrapper=a("<span>").addClass("custom-combobox").insertAfter(this.element),this.element.hide(),this._createAutocomplete(),this._createShowAllButton()},_createAutocomplete:function(){var b=this.element.children(":selected"),c=b.val()?b.text():"";this.input=a("<input>").appendTo(this.wrapper).val(c).attr("title","").addClass("custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left").autocomplete({delay:0,minLength:0,source:a.proxy(this,"_source")}).tooltip({tooltipClass:"ui-state-highlight"}),this._on(this.input,{autocompleteselect:function(a,b){b.item.option.selected=!0,this._trigger("select",a,{item:b.item.option})},autocompletechange:"_appendIfInvalid"})},_createShowAllButton:function(){var b=this.input,c=!1;a("<a>").attr("tabIndex",-1).attr("title","Show Existing Options").tooltip().appendTo(this.wrapper).button({icons:{primary:"ui-icon-triangle-1-s"},text:!1}).removeClass("ui-corner-all").addClass("custom-combobox-toggle ui-corner-right").mousedown(function(){c=b.autocomplete("widget").is(":visible")}).click(function(){b.focus(),c||b.autocomplete("search","")})},_source:function(b,c){var d=new RegExp(a.ui.autocomplete.escapeRegex(b.term),"i");c(this.element.children("option").map(function(){var c=a(this).text();if(this.value&&(!b.term||d.test(c)))return{label:c,value:c,option:this}}))},_appendIfInvalid:function(b,c){if(!c.item){var d=this.input.val(),e=d.toLowerCase(),f=!1;this.element.children("option").each(function(){if(a(this).text().toLowerCase()===e)return this.selected=f=!0,!1}),f||this.element.append("<option value='"+this.input.val()+"' selected='selected'>"+this.input.val()+"</otion>")}},_destroy:function(){this.wrapper.remove(),this.element.show()}})}(jQuery),$(function(){$("#combobox").combobox(),$("#toggle").click(function(){$("#combobox").toggle()})});