document.addEventListener('DOMContentLoaded', function () {

  // Scroll to top button
  const scrollBtn = document.querySelector('.scrolltotop');

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

  window.addEventListener('scroll', function () {
    if (window.scrollY > 500) {
      scrollBtn.style.display = 'block';
      scrollBtn.style.opacity = '1';
    } else {
      scrollBtn.style.opacity = '0';
      setTimeout(() => {
        scrollBtn.style.display = 'none';
      }, 300);
    }
  });
  


    // ✅ Gallery 1 Init
    var mainGallery1 = new Flickity('.gallery-main-1', {
      cellAlign: 'center',
      contain: true,
      pageDots: false,
      prevNextButtons: false,
      wrapAround: true,
      asNavFor: '.gallery-nav-1'
    });

    var navGallery1 = new Flickity('.gallery-nav-1', {
      asNavFor: '.gallery-main-1',
      contain: true,
      pageDots: false,
      wrapAround: true,
      prevNextButtons: true,
      cellAlign: 'left'
    });



document.addEventListener('DOMContentLoaded', function() {
    function animateCounter(counter) {
        const targetNumber = +counter.getAttribute('data-number');
        const duration = 1000; // 1 second
        let startTimestamp = null;

        const step = (timestamp) => {
            if (!startTimestamp) startTimestamp = timestamp;
            const progress = Math.min((timestamp - startTimestamp) / duration, 1);
            counter.innerText = Math.floor(progress * targetNumber).toLocaleString();
            if (progress < 1) {
                window.requestAnimationFrame(step);
            } else {
                counter.innerText = targetNumber.toLocaleString();
            }
        };

        window.requestAnimationFrame(step);
    }

    const observerCallback = (entries, observer) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                const counters = entry.target.querySelectorAll('.counter'); 
                counters.forEach(counter => animateCounter(counter));
                observer.unobserve(entry.target);
            }
        });
    };

    const observerOptions = {
        root: null,
        threshold: 0.1
    };

    const observer = new IntersectionObserver(observerCallback, observerOptions);
    const counterBox = document.getElementById('counter-box');
    observer.observe(counterBox);
});



// main
});