!function(a){a.fn.super_search=function(b){var c,d,e=this,f={},g={},h={current:"",previous:""};this.attr("ss_element","search_input");var i=a.extend({action:"super_search",ajax_url:ajaxurl,input_classes:{no_results:"ss_no_results",processing:"ss_processing",error:"ss_error"},response_classes:{response_wrapper:"ss_response_container",show_scroll:"ss_show_scroll",item_class:""},append_to:a(e).parent(),search_trigger:!1,search_result_gap:200,limit:5,timers:{abandonment:1e3,search_entry:2e3},async:!1,debug:!0,success:!1,beforeSend:!1,ui:{}},b);"function"!=typeof i.log&&(i.log=function(a){i.debug&&console.log(a)}),a(i.append_to).length||i.log("The ("+i.append_to+") element does not exist.","warning"),i.search_trigger&&"object"==typeof i.search_trigger&&a(i.search_trigger).click(function(){h.current!=h.previous&&a.fn.super_search.do_search()}),this.keyup(function(){return h.current=e.val(),d&&!h.current?void clearTimeout(d):void(h.current!=h.previous&&(d&&clearTimeout(d),d=setTimeout(a.fn.super_search.do_search,i.timers.search_entry)))}),this.focus(function(){a.fn.super_search.ux_change()}),this.blur(function(){a.fn.super_search.ux_change()}),a.fn.super_search.do_search=function(){i.log("do_search()"),h.current=e.val();var b={action:i.action,limit:i.limit,query:h.current};cb_data={post_data:b,settings:i},a.each(i.input_classes,function(b,c){a(e).removeClass(c)}),a(e).addClass(i.input_classes.processing),a.ajax({url:i.ajax_url,async:i.async,data:b,beforeSend:function(a,b){i.log("do_search.beforeSend() - have callback, executing"),cb_data.settings=b,"function"==typeof i.beforeSend&&i.beforeSend.call(this,cb_data)},complete:function(b,c){i.log("do_search.complete( jqXHR, "+c+" )"),a(e).removeClass(i.input_classes.processing),i.log("Ajax response received.")},success:function(b,c,d){i.log("do_search.success()"),"function"==typeof i.success&&(i.log("do_search.success() - have callback, executing"),i.success.call(b,c,d))||(h.previous=h.current,a.fn.super_search.remove_rendered_results(),b.results?(i.last_results=b.results,a.fn.super_search.render_results(b.results)):a(e).addClass(i.input_classes.no_results),b.other&&i.log("Search Debug Data:".data.debug_response))},error:function(){i.log("do_search.error()"),a(e).addClass(i.input_classes.error)},dataType:"json"})},a.fn.super_search.remove_rendered_results=function(){i.log("remove_rendered_results()"),i.rendered_element&&i.rendered_element.length&&a(i.rendered_element).fadeOut(300,function(){}),a.fn.super_search.update_dom_triggers()},a.fn.super_search.update_dom_triggers=function(){i.log("update_dom_triggers()"),a(i.rendered_element).off("mouseenter"),a(i.rendered_element).off("mouseleave"),a(i.rendered_element).mouseenter(function(){g.results_over=!0,a.fn.super_search.ux_change()}).mouseleave(function(){g.results_over=!1,a.fn.super_search.ux_change()})},a.fn.super_search.ux_change=function(){i.log("ux_change()"),a(e).is(":focus")?(g.input_focus=!0,h.current==h.previous&&i.rendered_element&&i.rendered_element.show()):g.input_focus=!1,i.rendered_element&&!g.input_focus&&g.results_over===!1?c=setTimeout(a.fn.super_search.remove_rendered_results,i.timers.abandonment):c&&clearTimeout(c)},a.fn.super_search.render_results=function(b){i.log("render_results()");var c=b.length-1;html=[],html.push(i.ui.response_container='<ul ss_element="response_container" class="ss_element '+i.response_classes.response_wrapper+'">'),console.log(i.ui.response_container),a.each(b,function(a,b){var d=[];i.response_classes.item_class&&d.push(i.response_classes.item_class),b.item_class&&d.push(b.item_class),a==c&&d.push("last_item"),html.push('<li ss_element="single_item" class="ss_element '+d.join(" ")+'">'),b.url&&html.push('<a href="'+b.url+'">'),html.push(b.title),b.url&&html.push("</a>"),html.push("</li>")}),html.push("</ul>"),i.rendered_element=a(html.join("")),a(i.append_to).append(i.rendered_element),f.window_height=a(window).height(),f.rendered_element=a(i.rendered_element).height(),f.rendered_element+i.search_result_gap>f.window_height&&(a(i.rendered_element).css("max-height",f.window_height-i.search_result_gap+"px"),a(i.rendered_element).addClass(i.response_classes.show_scroll),f.rendered_element=a(i.rendered_element).height()),a.fn.super_search.update_dom_triggers()}}}(jQuery);