$(function(){var ajaxsearchrequest=null;$("#top-search-term, #mobileSearch").autoComplete({delay:300,trimSearch:1,source:function(term,response){try{ajaxsearchrequest.abort()}catch(e){}ajaxsearchrequest=$.getJSON("/extscript/livesearch.php",{searchterm:term},function(data){sugg=[];window.firstsearchdone=1;response(data)})},renderItem:function(item,search){var suggestion="",html="";search=search.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&");var re=new RegExp("("+search.split(" ").join("|")+
")","gi");$.each(item,function(index,item){if(index=="info"){info=item;return}var string=item.string.replace(re,"$1");suggestion=suggestion+'
'+string+""});if(info.found==0)return html;html='";return html}})});
(function($){$.fn.autoComplete=function(options){var o=$.extend({},$.fn.autoComplete.defaults,options);if(typeof options=="string"){this.each(function(){var that=$(this);if(options=="destroy"){$(window).off("resize.autocomplete",that.updateSC);that.off("blur.autocomplete focus.autocomplete keydown.autocomplete keyup.autocomplete");if(that.data("autocomplete"))that.attr("autocomplete",that.data("autocomplete"));else that.removeAttr("autocomplete");$(that.data("sc")).remove();that.removeData("sc").removeData("autocomplete")}});
return this}return this.each(function(){var that=$(this);that.sc=$('');that.data("sc",that.sc).data("autocomplete",that.attr("autocomplete"));that.attr("autocomplete","off");that.cache={};that.last_val="";that.updateSC=function(resize,next){if(!resize){that.sc.show();that.sc.addClass("is-searching");$(".subSearch-block").addClass("is-searching");if(!that.sc.maxHeight)that.sc.maxHeight=parseInt(that.sc.css("max-height"));if(!that.sc.suggestionHeight)that.sc.suggestionHeight=
$(".result-item",that.sc).first().outerHeight();if(that.sc.suggestionHeight)if(!next)that.sc.scrollTop(0);else{var scrTop=that.sc.scrollTop(),selTop=next.offset().top-that.sc.offset().top;if(selTop+that.sc.suggestionHeight-that.sc.maxHeight>0)that.sc.scrollTop(selTop+that.sc.suggestionHeight+scrTop-that.sc.maxHeight);else if(selTop<0)that.sc.scrollTop(selTop+scrTop)}}};$(window).on("resize.autocomplete",that.updateSC);that.sc.appendTo(".subMenu-search");that.sc.on("mouseleave",".result-item",function(){$(".result-item.selected").removeClass("selected")});
that.sc.on("mouseenter",".result-item",function(){$(".result-item.selected").removeClass("selected");$(this).addClass("selected")});that.sc.on("mousedown click",".result-item",function(e){var item=$(this),v=item.data("val");if(v||item.hasClass("result-item")){that.val(v);o.onSelect(e,v,item);that.sc.removeClass("is-searching");$(".subSearch-block").removeClass("is-searching");that.sc.hide()}return false});that.on("blur.autocomplete",function(){try{over_sb=$(".subSuggest-block:hover").length}catch(e){over_sb=
0}if(!over_sb){that.last_val=that.val();that.sc.removeClass("is-searching");$(".subSearch-block").removeClass("is-searching");that.sc.hide();setTimeout(function(){that.sc.removeClass("is-searching");$(".subSearch-block").removeClass("is-searching");$(".subMenu-search").removeClass("is-focused");that.sc.hide()},350)}else if(!that.is(":focus"))setTimeout(function(){that.focus()},20)});if(!o.minChars)that.on("focus.autocomplete",function(){that.last_val="\n";that.trigger("keyup.autocomplete")});function suggest(data){if(o.trimSearch)var val=
that.val().replace(/\s+/g," ").trim();else var val=that.val();that.cache[val]=data;if(data.length&&val.length>=o.minChars){var s="";for(var i=0;i=
o.minChars){if(val!=that.last_val){that.last_val=val;clearTimeout(that.timer);if(o.cache){if(val in that.cache){suggest(that.cache[val]);return}for(var i=1;i'+item.replace(re,"$1")+""},onSelect:function(e,term,item){e.preventDefault();document.location=item.find("a").attr("href")}}})(jQuery);