/**
 * ITSWEBER CMS – Default Theme JavaScript
 * Mobile navigation + Scroll-to-Top (v3.0.6)
 * Gallery lightbox is now handled by /assets/js/gallery-lightbox.js
 */
document.addEventListener('DOMContentLoaded', function () {

    // -------------------------------------------------------------------------
    // Scroll-to-Top Button
    // -------------------------------------------------------------------------
    var scrollBtn = document.getElementById('scrollToTop');
    if (scrollBtn) {
        var scrollThreshold = 300;
        var ticking = false;

        function onScroll() {
            if (!ticking) {
                window.requestAnimationFrame(function () {
                    if (window.scrollY > scrollThreshold) {
                        scrollBtn.classList.add('is-visible');
                    } else {
                        scrollBtn.classList.remove('is-visible');
                    }
                    ticking = false;
                });
                ticking = true;
            }
        }

        window.addEventListener('scroll', onScroll, { passive: true });

        scrollBtn.addEventListener('click', function () {
            window.scrollTo({ top: 0, behavior: 'smooth' });
        });
    }

    // -------------------------------------------------------------------------
    // Mobile navigation toggle
    // -------------------------------------------------------------------------
    const navToggle = document.getElementById('navToggle');
    const navList   = document.getElementById('navList');

    if (navToggle && navList) {
        navToggle.addEventListener('click', function () {
            const isOpen = navList.classList.toggle('open');
            navToggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
        });
    }

});
