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^="include_terms"]'),l=i.find('input[name^="exclude_terms"]'),u=i.find('input[name="search_limit_to_post_titles"]'),c=i.find('input[name="add_woo_product_skus"]'),v=i.find('input[name="live_min_character"]'),f=i.find('input[name="live_posts_per_page"]'),h=i.find('input[name="live_search_display_featured_image"]'),p=i.find('input[name="live_search_display_post_type"]'),_=i.find('input[name="live_results_scrollbar"]'),m=o.closest(".fusion-builder-row"),g=i.closest(".fusion-header"),y=void 0!==v.val()?parseInt(v.val()):avadaLiveSearchVars.min_char_count,C=void 0!==f.val()?parseInt(f.val()):avadaLiveSearchVars.per_page,j=void 0!==h.val()?parseInt(h.val()):avadaLiveSearchVars.show_feat_img,S=void 0!==p.val()?parseInt(p.val()):avadaLiveSearchVars.display_post_type;function L(s){var e="";o.html(""),o.removeClass("suggestions-empty"),o.addClass("suggestions-added"),Q("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 b(){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(),y<=a.val().length){if(void 0!==s[e])return void L(s[e]);i.find(".fusion-slider-loading").show(),i.find(".fusion-search-submit").css("color","transparent"),n.css("color","transparent");let o={action:"live_search_retrieve_posts",search:a.val(),per_page:C,show_feat_img:j,display_post_type:S,post_type:t(),search_limit_to_post_titles:u.val(),add_woo_product_skus:c.val()};d.length&&(o.include_terms=d.val()),l.length&&(o.exclude_terms=l.val()),jQuery.ajax({url:avadaLiveSearchVars.ajaxurl,type:"post",data:o}).done((function(a){s[e]=a,L(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"),Q("remove")}function Q(s){m.length&&("add"===s?m.css("z-index","11"):m.css("z-index","")),g.length&&("add"===s?g.addClass("live-suggestion-added"):g.removeClass("live-suggestion-added"))}n.attr("data-color",n.css("color")),void 0!==_.val()&&_.val()&&o.addClass("live-results-scrollbar-"+_.val()),a.on("focusin",(function(){y<=jQuery(this).val().length&&o.children(".fusion-search-result").length&&(o.addClass("suggestions-added"),Q("add"))})),a.on("focusout",(function(){o.is(":hover")||t.is(":hover")||(o.removeClass("suggestions-added"),Q("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"),Q("remove"),o.addClass("suggestions-transition"),setTimeout((function(){o.removeClass("suggestions-transition")}),300))})),a.on("keyup",(function(){clearTimeout(e),e=setTimeout(b,500)})),a.on("keydown",(function(){clearTimeout(e)}))}))};jQuery(document).ready((function(){avadaLiveSearch()}));