(function () { 'use strict'; var stage = document.querySelector('[data-btp581-stage]'); if (!stage) return; var windows = Array.prototype.slice.call(stage.querySelectorAll('[data-btp581-domain]')); if (!windows.length) return; var reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)'); var desktopLayout = window.matchMedia('(min-width: 861px)'); var activeIndex = 0; var timer = 0; var stageVisible = true; var userHolding = false; function setActive(index) { activeIndex = (index + windows.length) % windows.length; windows.forEach(function (item, itemIndex) { item.classList.toggle('is-active', itemIndex === activeIndex); }); stage.setAttribute('data-active-domain', windows[activeIndex].getAttribute('data-btp581-domain')); } function stopCycle() { if (!timer) return; window.clearInterval(timer); timer = 0; } function canCycle() { return !reducedMotion.matches && desktopLayout.matches && !document.hidden && stageVisible && !userHolding; } function startCycle() { stopCycle(); if (!canCycle()) return; timer = window.setInterval(function () { setActive(activeIndex + 1); }, 4800); } windows.forEach(function (item, index) { item.addEventListener('pointerenter', function () { userHolding = true; stopCycle(); setActive(index); }, { passive: true }); item.addEventListener('focus', function () { userHolding = true; stopCycle(); setActive(index); }); }); stage.addEventListener('pointerleave', function () { userHolding = false; startCycle(); }, { passive: true }); stage.addEventListener('focusout', function (event) { if (stage.contains(event.relatedTarget)) return; userHolding = false; startCycle(); }); function handleEnvironmentChange() { if (!desktopLayout.matches) { stopCycle(); setActive(0); return; } startCycle(); } if (typeof reducedMotion.addEventListener === 'function') { reducedMotion.addEventListener('change', handleEnvironmentChange); desktopLayout.addEventListener('change', handleEnvironmentChange); } else { reducedMotion.addListener(handleEnvironmentChange); desktopLayout.addListener(handleEnvironmentChange); } document.addEventListener('visibilitychange', startCycle); if ('IntersectionObserver' in window) { var visibilityObserver = new IntersectionObserver(function (entries) { stageVisible = Boolean(entries[0] && entries[0].isIntersecting); startCycle(); }, { threshold: 0.16 }); visibilityObserver.observe(stage); } window.addEventListener('pagehide', stopCycle, { once: true }); setActive(0); startCycle(); }());