let wrapper_id=0,scrollPosition=0;const initializationTracker={singleImages:new Set,galleries:new Set,fancyboxBound:!1};function cleanUrl(e){return e.replace("https://www.searchenginejournal.com/wp-content/uploads","")}function downloadImage(e,o="image"){const t=document.createElement("a");if(t.href=e,"image"===o||!o){const t=e.split("/");o=t[t.length-1]||"downloaded-image.jpg"}t.download=o,t.target="_blank",fetch(e).then((e=>{if(e.ok)return e.blob();throw new Error("CORS blocked or network error")})).then((e=>{const o=URL.createObjectURL(e);t.href=o,document.body.appendChild(t),t.click(),document.body.removeChild(t),setTimeout((()=>URL.revokeObjectURL(o)),100)})).catch((()=>{t.href=e,document.body.appendChild(t),t.click(),document.body.removeChild(t)}))}function saveScrollPosition(){scrollPosition=window.pageYOffset||document.documentElement.scrollTop}function restoreScrollPosition(){setTimeout((()=>{document.body.style.overflow="",document.documentElement.style.overflow="",document.body.style.position="",document.body.style.top="",window.scrollTo(0,scrollPosition)}),50)}function destroyExistingFancybox(){try{Fancybox.destroy(),initializationTracker.fancyboxBound=!1}catch(e){}}function processSingleImages(){$(".sej-has-fancy .wp-caption img").not(".fancybox-processed").not(".small-img").each((function(){let e=$(this),o=e.closest(".wp-caption"),t=o.attr("id")||"img-"+Date.now()+"-"+Math.random().toString(36).substr(2,9);if(!initializationTracker.singleImages.has(t)){if(!e.parent().is("a")){let t="",a=o.find(".wp-caption-text");a.length?t=a.text().trim():e.attr("alt")&&(t=e.attr("alt")),e.wrap("")}e.addClass("fancybox-processed"),initializationTracker.singleImages.add(t)}}))}function processGalleries(e=".sej-has-fancy .gallery"){$(e).not(".fancybox-gallery-processed").each((function(e){let o=$(this),t=o.attr("id")||"gallery-"+wrapper_id+"-"+e;if(initializationTracker.galleries.has(t))return;let a=o.find(".gallery-item a"),n="gallery-"+t;switch(a.each((function(){let e=$(this);if(!e.attr("data-fancybox")){e.attr("data-fancybox",n);let o="",t=e.closest(".gallery-item").find(".wp-caption-text, .gallery-caption");t.length&&(o=t.text().trim()),e.attr("data-caption",o)}})),a.length){case 2:o.addClass("gal-2-col");break;case 3:o.addClass("gal-3-col")}let i=3;window.innerWidth<600&&(i=1),a.length>i&&!o.hasClass("owl-carousel")&&(o.addClass("owl-carousel"),o.owlCarousel({nav:!0,dots:!1,items:3,loop:!1,lazyLoad:!0,responsive:{0:{items:1},575:{items:2},768:{items:3}}})),o.addClass("fancybox-gallery-processed"),initializationTracker.galleries.add(t)}))}function initializeFancybox(){if(initializationTracker.fancyboxBound)return;$("body").hasClass("post-template-template-cover-story-bootstrap");destroyExistingFancybox();let e={autoFocus:!1,trapFocus:!1,placeFocusBack:!1,groupAll:!1,groupAttr:!1,Carousel:{Navigation:!1,Toolbar:{display:{left:[],middle:[],right:["download","close"]}}},on:{init:e=>{saveScrollPosition()},destroy:e=>{restoreScrollPosition()},"Carousel.contentReady":(e,o,t)=>{void 0!==t.src&&"function"==typeof __gaTrackers&&__gaTrackers("send","event","Image Zoom",window.location.pathname,cleanUrl(t.src))},close:e=>{setTimeout((()=>{document.body.classList.remove("compensate-for-scrollbar"),restoreScrollPosition()}),10)},"Carousel.click":(e,o,t)=>{if(t.target.closest("[data-fancybox-download]")){t.preventDefault(),t.stopPropagation();const e=o.getSlide();return e&&e.src&&downloadImage(e.src,e.caption||"image"),!1}}}},o={autoFocus:!1,trapFocus:!1,placeFocusBack:!1,groupAll:!1,Carousel:{Navigation:!0,Toolbar:{display:{left:[],middle:[],right:["download","close"]}}},on:{init:e=>{saveScrollPosition()},"Carousel.contentReady":(e,o,t)=>{void 0!==t.src&&"function"==typeof __gaTrackers&&__gaTrackers("send","event","Image Zoom",window.location.pathname,cleanUrl(t.src))},destroy:e=>{restoreScrollPosition()},close:e=>{setTimeout((()=>{document.body.classList.remove("compensate-for-scrollbar"),restoreScrollPosition()}),10)},"Carousel.click":(e,o,t)=>{if(t.target.closest("[data-fancybox-download]")){t.preventDefault(),t.stopPropagation();const e=o.getSlide();return e&&e.src&&downloadImage(e.src,e.caption||"image"),!1}}}};Fancybox.bind('[data-fancybox="single-images"]',e),Fancybox.bind('[data-fancybox^="gallery-"]',o),initializationTracker.fancyboxBound=!0}function initializeLightbox(){processSingleImages(),processGalleries(),initializeFancybox()}$(document).ready((function(){initializeLightbox()})),window.addEventListener("inf_article_load",(function(){wrapper_id++,setTimeout((function(){processSingleImages(),processGalleries("#wrapper_"+wrapper_id+" .gallery"),initializationTracker.fancyboxBound||initializeFancybox()}),100)})),window.addEventListener("focus",(function(){"hidden"!==document.body.style.overflow||document.querySelector(".fancybox__container")||restoreScrollPosition()})),window.addEventListener("pageshow",(function(e){e.persisted&&restoreScrollPosition()})),document.addEventListener("keydown",(function(e){"Escape"!==e.key||"hidden"!==document.body.style.overflow||document.querySelector(".fancybox__container")||restoreScrollPosition()})),window.resetFancyboxTracker=function(){initializationTracker.singleImages.clear(),initializationTracker.galleries.clear(),initializationTracker.fancyboxBound=!1,destroyExistingFancybox()};