(function(a){a.fn.autoSuggest=function(s,d){d=a.extend({minCharacters:1,maxResults:10,wildCard:"",caseSensitive:false,notCharacter:"!",maxHeight:350,highlightMatches:true,onSelect:undefined,OverMouse:undefined},d);return this.each(function(){function l(b,c){var h=["/",".","*","+","?","|","(",")","[","]","{","}","\\"];if(c)for(var g=0;g<h.length;g++)h[g]===c&&h.splice(g,1);c=new RegExp("(\\"+h.join("|\\")+")","g");return b.replace(c,"\\$1")}function t(b){i.val(b.text);a(e).html("").hide();typeof d.onSelect=== "function"&&d.onSelect(b)}function u(b){i.val(b.text);typeof d.onSelect==="function"&&d.onSelect(b)}function m(b){a("div.resultItem",e).removeClass("hover");a(b).addClass("hover");f=b}function v(){a(e).html("").hide()}function w(b,c){c="("+c+")";var h=true,g=0,n=d.caseSensitive?new RegExp(c,"g"):new RegExp(c,"ig");a(e).html("").hide();for(c=0;c<b.length;c++){var j=a("<div />"),o=b[c].text;if(d.highlightMatches===true)o=o.replace(n,"<strong>$1</strong>");a(j).append('<p class="text">'+o+"</p>");a(j).addClass("resultItem").addClass(h? "odd":"even").click(function(k){return function(){t(b[k])}}(c)).mouseover(function(k){return function(){u(b[k])}}(c)).mouseover(function(k){return function(){m(k)}}(j));a(e).append(j);h=!h;g+=1;if(typeof d.maxResults==="number"&&g>=d.maxResults)break}if(a("div",e).length>0){cuurentSelection=undefined;a(e).show().css("height","auto");a(e).height()>d.maxHeight&&a(e).css({overflow:"auto",height:d.maxHeight+"px"})}}function x(){if(this.value.length<d.minCharacters){a(e).html("").hide();return false}var b= [],c=!d.wildCard?l(this.value):l(this.value,d.wildCard).replace(y,".*"),h=true;if(d.notCharacter&&c.indexOf(d.notCharacter)===0){c=c.substr(d.notCharacter.length,c.length);if(c.length>0)h=false}c=c||".*";c=d.wildCard?"^"+c:c;a.ajaxSetup({error:function(g,n,j){alert(n);alert(j);alert(g.responseText)}});a.ajax({type:"get",url:s+"?prefix="+i.val(),success:function(g){if(g!=""){b=eval("("+g+")");w(b,c)}else v()}})}function r(b){if(!b)b=window.event;switch(b.keyCode){case 13:a(f).trigger("click");return false; case 40:f=typeof f==="undefined"?a("div.resultItem:first",e).get(0):a(f).next().get(0);m(f);f&&a(e).scrollTop(f.offsetTop);a(f).trigger("mouseover");return false;case 38:f=typeof f==="undefined"?a("div.resultItem:last",e).get(0):a(f).prev().get(0);m(f);f&&a(e).scrollTop(f.offsetTop);a(f).trigger("mouseover");return false;default:x.apply(this,[b]);break}}var i=a(this),y=new RegExp(l(d.wildCard||""),"g"),e=a("<div />"),f,p,q;a(e).addClass("jsonSuggestResults").css({top:i.position().top+i.height()+10+ "px",left:i.position().left+"px",width:i.width()+5+"px"}).hide();i.after(e).keyup(r).blur(function(){var b=a(e).position();b.bottom=b.top+a(e).height();b.right=b.left+a(e).width();if(q<b.top||q>b.bottom||p<b.left||p>b.right)a(e).hide()}).focus(function(){a("div",e).length>0&&a(e).show()});a().mousemove(function(b){p=b.pageX;q=b.pageY});a.browser.opera&&i.keydown(function(b){if(b.keyCode==40)return r(b)});d.noCharacter=l(d.notCharacter||"")})}})(jQuery);
