// Page interactions for accueil.html
(function () {
    'use strict';

    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('is-visible');
                observer.unobserve(entry.target);
            }
        });
    }, { threshold: 0.12 });
    document.querySelectorAll('.reveal').forEach(el => observer.observe(el));

    const heroBg = document.querySelector('.hero-bg');
    const heroImages = [
        'images/evenements/gouvernance/DSC_0210.jpg',
        'images/evenements/gouvernance/DSC_2962.jpg',
        'images/evenements/gouvernance/DSC_2981.jpg',
        'images/evenements/gouvernance/famillezoo02.jpg',
        'images/evenements/gouvernance/famillezoo05.jpg'
    ];

    if (heroBg && heroImages.length) {
        let currentIndex = 0;

        const setHeroImage = (index) => {
            heroBg.style.backgroundImage = `url('${heroImages[index]}')`;
            heroBg.style.backgroundPosition = 'center';
            heroBg.style.backgroundSize = 'cover';
            heroBg.style.backgroundRepeat = 'no-repeat';
        };

        const preloadImage = (src) => {
            const img = new Image();
            img.src = src;
        };

        heroImages.forEach(preloadImage);
        setHeroImage(currentIndex);

        window.setInterval(() => {
            currentIndex = (currentIndex + 1) % heroImages.length;
            setHeroImage(currentIndex);
        }, 7000);
    }
})();
