var avadaLiveSearch=function(){var s=[];avadaLiveSearchVars.live_search&&jQuery(".fusion-live-search-input").each(function(){var e,a=jQuery(this),i=a.closest(".fusion-live-search"),t=i.find(".fusion-search-button"),n=i.find(".fusion-search-submit"),o=i.find(".fusion-search-results"),r=i.find('input[name^="post_type"]'),d=i.find('input[name="search_limit_to_post_titles"]'),l=i.find('input[name="live_min_character"]'),u=i.find('input[name="live_posts_per_page"]'),c=i.find('input[name="live_search_display_featured_image"]'),v=i.find('input[name="live_search_display_post_type"]'),f=i.find('input[name="live_results_scrollbar"]'),h=o.closest(".fusion-builder-row"),p=i.closest(".fusion-header"),g=void 0!==l.val()?parseInt(l.val()):avadaLiveSearchVars.min_char_count,_=void 0!==u.val()?parseInt(u.val()):avadaLiveSearchVars.per_page,m=void 0!==c.val()?parseInt(c.val()):avadaLiveSearchVars.show_feat_img,y=void 0!==v.val()?parseInt(v.val()):avadaLiveSearchVars.display_post_type;function C(s){var e="";o.html(""),o.removeClass("suggestions-empty"),o.addClass("suggestions-added"),S("add"),jQuery.isEmptyObject(s)?(o.addClass("suggestions-empty"),e+='<div class="fusion-search-result">'+avadaLiveSearchVars.no_search_results+"</div>",o.append(e)):jQuery.each(s,function(s,a){e="",e+='<a class="fusion-search-result" href="'+a.post_url+'" title="'+a.title+'">',a.image_url&&(e+='<div class="fusion-search-image"><img class="fusion-search-image-tag" src="'+a.image_url+'" alt="Post Thumb'+a.id+'"/></div>'),e+='<div class="fusion-search-content">',e+='<div class="fusion-search-post-title">'+a.title+"</div>",a.type&&(e+='<div class="fusion-search-post-type">'+a.type+"</div>"),e+="</div>",e+="</a>",o.append(e)})}function j(){var e,t;if(i=a.closest(".fusion-live-search"),e=a.val(),e+=(t=function(){var s=[];return r.each(function(){s.push(this.value)}),s})().toString(),g<=a.val().length){if(void 0!==s[e])return void C(s[e]);i.find(".fusion-slider-loading").show(),i.find(".fusion-search-submit").css("color","transparent"),n.css("color","transparent"),jQuery.ajax({url:avadaLiveSearchVars.ajaxurl,type:"post",data:{action:"live_search_retrieve_posts",search:a.val(),per_page:_,show_feat_img:m,display_post_type:y,post_type:t(),search_limit_to_post_titles:d.val()}}).done(function(a){s[e]=a,C(a),i.find(".fusion-slider-loading").hide(),n.css("color",n.attr("data-color"))})}else i.find(".fusion-slider-loading").hide(),n.css("color",n.attr("data-color")),o.removeClass("suggestions-added"),S("remove")}function S(s){h.length&&("add"===s?h.css("z-index","11"):h.css("z-index","")),p.length&&("add"===s?p.addClass("live-suggestion-added"):p.removeClass("live-suggestion-added"))}n.attr("data-color",n.css("color")),void 0!==f.val()&&f.val()&&o.addClass("live-results-scrollbar-"+f.val()),a.on("focusin",function(){g<=jQuery(this).val().length&&o.children(".fusion-search-result").length&&(o.addClass("suggestions-added"),S("add"))}),a.on("focusout",function(){o.is(":hover")||t.is(":hover")||(o.removeClass("suggestions-added"),S("remove"),o.addClass("suggestions-transition"),setTimeout(function(){o.removeClass("suggestions-transition")},300))}),jQuery(t,o).on("mouseleave",function(){a.is(":focus")||(o.removeClass("suggestions-added"),S("remove"),o.addClass("suggestions-transition"),setTimeout(function(){o.removeClass("suggestions-transition")},300))}),a.on("keyup",function(){clearTimeout(e),e=setTimeout(j,500)}),a.on("keydown",function(){clearTimeout(e)})})};jQuery(document).ready(function(){avadaLiveSearch()});