
(function(){
  function ready(fn){ if(document.readyState==='loading') document.addEventListener('DOMContentLoaded',fn); else fn(); }
  ready(function(){
    document.documentElement.style.overflowY='auto';
    document.documentElement.style.touchAction='pan-y';
    document.body.style.overflowY='auto';
    document.body.style.height='auto';
    document.body.style.touchAction='pan-y';
    document.body.classList.remove('menu-open');
    var loader=document.querySelector('.site-loader');
    setTimeout(function(){ document.body.classList.add('loaded'); if(loader){ loader.classList.add('is-hiding'); loader.style.pointerEvents='none'; } }, 700);
    setTimeout(function(){ if(loader && loader.parentNode){ loader.parentNode.removeChild(loader); } }, 1300);

    var menuBtn=document.getElementById('menuToggle');
    var menu=document.getElementById('mobileMenu');
    var closeBtn=document.getElementById('closeMenu');
    if(menuBtn && menu){ menuBtn.onclick=function(e){ e.preventDefault(); e.stopPropagation(); menu.classList.add('show'); document.body.classList.add('menu-open'); }; }
    function closeMenu(){ if(menu){ menu.classList.remove('show'); } document.body.classList.remove('menu-open'); document.body.style.overflowY='auto'; }
    if(closeBtn){ closeBtn.onclick=function(e){ e.preventDefault(); closeMenu(); }; }
    if(menu){ menu.querySelectorAll('a').forEach(function(a){ a.addEventListener('click', closeMenu); }); }

    document.querySelectorAll('.home-hero-slider').forEach(function(slider){
      var slides=Array.prototype.slice.call(slider.querySelectorAll('.slide'));
      if(!slides.length || slider.dataset.finalSliderReady) return;
      slider.dataset.finalSliderReady='1';
      var i=0; slides.forEach(function(s,idx){ s.classList.toggle('active', idx===0); });
      setInterval(function(){ slides[i].classList.remove('active'); i=(i+1)%slides.length; slides[i].classList.add('active'); }, 4300);
    });
  });
})();
