(()=>{"use strict";function t(t,e){let o;return function(...n){clearTimeout(o),o=setTimeout((()=>t.apply(this,n)),e)}}const e=["#masthead","#primary",".above-footer-widgets",".scaip .newspack_global_ad","#colophon",".newspack_global_ad.sticky"];function o(e,o,n){const i=document.querySelector("#primary");if(!i)return;const s=document.querySelector(e);if(!s)return;s.style.right="auto";const d=s.querySelector("div");if(!d)return;d.classList.add("ad-slot");const l=document.querySelector("#masthead"),c=document.createElement("div");c.style.width=(d._size?d._size[0]:d.offsetWidth)+"px",c.style.height=(d._size?d._size[1]:d.offsetHeight)+"px",c.style.position="absolute",c.style.pointerEvents="none",s.prepend(c);const r=()=>{d.classList.add("ad-hidden"),d.classList.remove("ad-visible")},a=()=>{(()=>{const t=document.querySelector(".newspack_global_ad.sticky"),e=document.querySelector(".newspack_sticky_ad__close");t&&(s.style.bottom=`${t.offsetHeight}px`),e&&e.addEventListener("click",(()=>{s.style.removeProperty("bottom"),a()}))})(),(()=>{if(document.body.classList.contains("h-stk")){const t=l.getBoundingClientRect();s.style.top=`${t.bottom}px`}const t=i.getBoundingClientRect();let e=0;"left"===o?(s.style.left="0",e=t.left):(s.style.left=`${t.right}px`,e=window.innerWidth-t.right),s.style.width=`${e}px`})(),d.style.width&&parseInt(d.style.width.replace("px",""))>s.offsetWidth||function(t,e){const o=t.getBoundingClientRect();return o.left<0||window.innerWidth{const e=t.getBoundingClientRect();return!(o.right<=e.left||o.left>=e.right||o.bottom<=e.top||o.top>=e.bottom)}))}(c,n)?r():(d.classList.remove("ad-hidden"),d.classList.add("ad-visible"),d.style.removeProperty("display"))};a(),window.addEventListener("scroll",t(a,50)),window.addEventListener("resize",t(a,200)),window.googletag.cmd.push((function(){window.googletag.pubads().addEventListener("slotRenderEnded",(function(t){d.id===t.slot.getSlotElementId()&&(c.style.width=t.size[0]+"px",c.style.height=t.size[1]+"px",a())}))}))}var n;window.googletag=window.googletag||{cmd:[]},n=()=>{const t=document.querySelectorAll(e.join(","));o(".newspack_global_ad.left_side_rail","left",t),o(".newspack_global_ad.right_side_rail","right",t)},"undefined"!=typeof document&&("complete"!==document.readyState&&"interactive"!==document.readyState?document.addEventListener("DOMContentLoaded",n):n())})();