/*
 * jQuery UI Autocomplete 1.8.1
 *
 * Copyright (c) 2010 AUTHORS.txt (http://jqueryui.com/about)
 * Dual licensed under the MIT (MIT-LICENSE.txt)
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 * http://docs.jquery.com/UI/Autocomplete
 *
 * Depends:
 *	jquery.ui.core.js
 *	jquery.ui.widget.js
 *	jquery.ui.position.js
 */

(function(c){c.widget("ui.autocomplete",{options:{minLength:1,delay:300},_create:function(){var a=this,b=this.element[0].ownerDocument;this.element.addClass("ui-autocomplete-input").attr("autocomplete","off").attr({role:"textbox","aria-autocomplete":"list","aria-haspopup":"true"}).bind("keydown.autocomplete",function(b){var d=c.ui.keyCode;switch(b.keyCode){case d.PAGE_UP:a._move("previousPage",b);break;case d.PAGE_DOWN:a._move("nextPage",b);break;case d.UP:a._move("previous",b);b.preventDefault();
break;case d.DOWN:a._move("next",b);b.preventDefault();break;case d.ENTER:a.menu.active&&b.preventDefault();case d.TAB:if(!a.menu.active)break;a.menu.select(b);break;case d.ESCAPE:a.element.val(a.term);a.close(b);break;case d.LEFT:case d.RIGHT:case d.SHIFT:case d.CONTROL:case d.ALT:break;default:clearTimeout(a.searching),a.searching=setTimeout(function(){a.search(null,b)},a.options.delay)}}).bind("focus.autocomplete",function(){a.selectedItem=null;a.previous=a.element.val()}).bind("blur.autocomplete",
function(b){clearTimeout(a.searching);a.closing=setTimeout(function(){a.close(b);a._change(b)},150)});this._initSource();this.response=function(){return a._response.apply(a,arguments)};this.menu=c("<ul></ul>").addClass("ui-autocomplete").appendTo("body",b).menu({focus:function(b,d){var c=d.item.data("item.autocomplete");!1!==a._trigger("focus",null,{item:c})&&/^key/.test(b.originalEvent.type)&&a.element.val(c.value)},selected:function(c,d){var f=d.item.data("item.autocomplete");!1!==a._trigger("select",
c,{item:f})&&a.element.val(f.value);a.close(c);var g=a.previous;if(a.element[0]!==b.activeElement)a.element.focus(),a.previous=g;a.selectedItem=f},blur:function(){a.menu.element.is(":visible")&&a.element.val(a.term)}}).zIndex(this.element.zIndex()+1).css({top:0,left:0}).hide().data("menu");c.fn.bgiframe&&this.menu.element.bgiframe()},destroy:function(){this.element.removeClass("ui-autocomplete-input").removeAttr("autocomplete").removeAttr("role").removeAttr("aria-autocomplete").removeAttr("aria-haspopup");
this.menu.element.remove();c.Widget.prototype.destroy.call(this)},_setOption:function(a){c.Widget.prototype._setOption.apply(this,arguments);a==="source"&&this._initSource()},_initSource:function(){var a,b;c.isArray(this.options.source)?(a=this.options.source,this.source=function(b,d){d(c.ui.autocomplete.filter(a,b.term))}):typeof this.options.source==="string"?(b=this.options.source,this.source=function(a,d){c.getJSON(b,a,d)}):this.source=this.options.source},search:function(a,b){a=a!=null?a:this.element.val();
if(a.length<this.options.minLength)return this.close(b);clearTimeout(this.closing);if(this._trigger("search")!==!1)return this._search(a)},_search:function(a){this.term=this.element.addClass("ui-autocomplete-loading").val();this.source({term:a},this.response)},_response:function(a){a.length?(a=this._normalize(a),this._suggest(a),this._trigger("open")):this.close();this.element.removeClass("ui-autocomplete-loading")},close:function(a){clearTimeout(this.closing);this.menu.element.is(":visible")&&(this._trigger("close",
a),this.menu.element.hide(),this.menu.deactivate())},_change:function(a){this.previous!==this.element.val()&&this._trigger("change",a,{item:this.selectedItem})},_normalize:function(a){if(a.length&&a[0].label&&a[0].value)return a;return c.map(a,function(a){if(typeof a==="string")return{label:a,value:a};return c.extend({label:a.label||a.value,value:a.value||a.label},a)})},_suggest:function(a){var b=this.menu.element.empty().zIndex(this.element.zIndex()+1),c;this._renderMenu(b,a);this.menu.deactivate();
this.menu.refresh();this.menu.element.show().position({my:"left top",at:"left bottom",of:this.element,collision:"none"});a=b.width("").width();c=this.element.width();b.width(Math.max(a,c))},_renderMenu:function(a,b){var e=this;c.each(b,function(b,c){e._renderItem(a,c)})},_renderItem:function(a,b){return c("<li></li>").data("item.autocomplete",b).append("<a>"+b.label+"</a>").appendTo(a)},_move:function(a,b){if(this.menu.element.is(":visible"))if(this.menu.first()&&/^previous/.test(a)||this.menu.last()&&
/^next/.test(a))this.element.val(this.term),this.menu.deactivate();else this.menu[a](b);else this.search(null,b)},widget:function(){return this.menu.element}});c.extend(c.ui.autocomplete,{escapeRegex:function(a){return a.replace(/([\^\$\(\)\[\]\{\}\*\.\+\?\|\\])/gi,"\\$1")},filter:function(a,b){var e=RegExp(c.ui.autocomplete.escapeRegex(b),"i");return c.grep(a,function(a){return e.test(a.label||a.value||a)})}})})(jQuery);
(function(c){c.widget("ui.menu",{_create:function(){var a=this;this.element.addClass("ui-menu ui-widget ui-widget-content ui-corner-all").attr({role:"listbox","aria-activedescendant":"ui-active-menuitem"}).click(function(b){c(b.target).closest(".ui-menu-item a").length&&(b.preventDefault(),a.select(b))});this.refresh()},refresh:function(){var a=this;this.element.children("li:not(.ui-menu-item):has(a)").addClass("ui-menu-item").attr("role","menuitem").children("a").addClass("ui-corner-all").attr("tabindex",
-1).mouseenter(function(b){a.activate(b,c(this).parent())}).mouseleave(function(){a.deactivate()})},activate:function(a,b){this.deactivate();if(this.hasScroll()){var c=b.offset().top-this.element.offset().top,d=this.element.attr("scrollTop"),f=this.element.height();c<0?this.element.attr("scrollTop",d+c):c>f&&this.element.attr("scrollTop",d+c-f+b.height())}this.active=b.eq(0).children("a").addClass("ui-state-hover").attr("id","ui-active-menuitem").end();this._trigger("focus",a,{item:b})},deactivate:function(){if(this.active)this.active.children("a").removeClass("ui-state-hover").removeAttr("id"),
this._trigger("blur"),this.active=null},next:function(a){this.move("next",".ui-menu-item:first",a)},previous:function(a){this.move("prev",".ui-menu-item:last",a)},first:function(){return this.active&&!this.active.prev().length},last:function(){return this.active&&!this.active.next().length},move:function(a,b,c){this.active?(a=this.active[a+"All"](".ui-menu-item").eq(0),a.length?this.activate(c,a):this.activate(c,this.element.children(b))):this.activate(c,this.element.children(b))},nextPage:function(a){if(this.hasScroll())if(!this.active||
this.last())this.activate(a,this.element.children(":first"));else{var b=this.active.offset().top,e=this.element.height(),d=this.element.children("li").filter(function(){var a=c(this).offset().top-b-e+c(this).height();return a<10&&a>-10});d.length||(d=this.element.children(":last"));this.activate(a,d)}else this.activate(a,this.element.children(!this.active||this.last()?":first":":last"))},previousPage:function(a){if(this.hasScroll())if(!this.active||this.first())this.activate(a,this.element.children(":last"));
else{var b=this.active.offset().top,e=this.element.height();result=this.element.children("li").filter(function(){var a=c(this).offset().top-b+e-c(this).height();return a<10&&a>-10});result.length||(result=this.element.children(":first"));this.activate(a,result)}else this.activate(a,this.element.children(!this.active||this.first()?":last":":first"))},hasScroll:function(){return this.element.height()<this.element.attr("scrollHeight")},select:function(a){this._trigger("selected",a,{item:this.active})}})})(jQuery);
