const carousels = [
            { index: 0, currentSlide: 0, slides: null, dots: null, autoTimer: null },
            { index: 1, currentSlide: 0, slides: null, dots: null, autoTimer: null },
            { index: 2, currentSlide: 0, slides: null, dots: null, autoTimer: null }
        ];

        // Initialize all carousels
        function initCarousels() {
            const containers = document.querySelectorAll('.carousel-container');
            containers.forEach((container, idx) => {
                carousels[idx].slides = container.querySelectorAll('.carousel-slide');
                carousels[idx].dots = container.querySelectorAll('.dot');
                startAutoSlide(idx);
            });
        }

        function showSlide(carouselIdx, slideIdx) {
            const carousel = carousels[carouselIdx];
            carousel.slides.forEach(slide => slide.classList.remove('active'));
            carousel.dots.forEach(dot => dot.classList.remove('active'));

            carousel.slides[slideIdx].classList.add('active');
            carousel.dots[slideIdx].classList.add('active');
            carousel.currentSlide = slideIdx;
        }

        function nextSlide(carouselIdx) {
            clearTimeout(carousels[carouselIdx].autoTimer);
            const carousel = carousels[carouselIdx];
            const nextIdx = (carousel.currentSlide + 1) % carousel.slides.length;
            showSlide(carouselIdx, nextIdx);
            startAutoSlide(carouselIdx);
        }

        function prevSlide(carouselIdx) {
            clearTimeout(carousels[carouselIdx].autoTimer);
            const carousel = carousels[carouselIdx];
            const prevIdx = (carousel.currentSlide - 1 + carousel.slides.length) % carousel.slides.length;
            showSlide(carouselIdx, prevIdx);
            startAutoSlide(carouselIdx);
        }

        function currentSlide(carouselIdx, slideIdx) {
            clearTimeout(carousels[carouselIdx].autoTimer);
            showSlide(carouselIdx, slideIdx);
            startAutoSlide(carouselIdx);
        }

        function startAutoSlide(carouselIdx) {
            carousels[carouselIdx].autoTimer = setTimeout(() => {
                nextSlide(carouselIdx);
            }, 6000);
        }

        // Initialize on load
        window.addEventListener('load', initCarousels);