document.addEventListener('DOMContentLoaded', function() {
    // Simple carousel functionality
    const carousel = document.querySelector('#carouselInner');
    const slides = carousel.querySelectorAll('.carousel-slide');
    const indicators = document.querySelectorAll('.indicator');
    const prevButton = document.querySelector('.carousel-control-prev');
    const nextButton = document.querySelector('.carousel-control-next');
    
    let currentIndex = 0;
    let interval;
    
    if (slides.length <= 1) return; // Don't initialize if only one slide
    
    // Function to show a specific slide
    function showSlide(index) {
        // Hide all slides
        slides.forEach(slide => slide.classList.remove('active'));
        indicators.forEach(indicator => indicator.classList.remove('active'));
        
        // Show the selected slide
        slides[index].classList.add('active');
        if (indicators.length > 0) {
            indicators[index].classList.add('active');
        }
        
        currentIndex = index;
    }
    
    // Function to go to next slide
    function nextSlide() {
        let nextIndex = (currentIndex + 1) % slides.length;
        showSlide(nextIndex);
    }
    
    // Auto-advance the carousel every 5 seconds
    function startAutoPlay() {
        interval = setInterval(nextSlide, 5000);
    }
    
    // Stop auto-play when user interacts with carousel
    function stopAutoPlay() {
        clearInterval(interval);
    }
    
    // Initialize carousel
    showSlide(0);
    startAutoPlay();
    
    // Add event listeners for manual navigation
    if (prevButton && nextButton) {
        prevButton.addEventListener('click', function(e) {
            e.preventDefault();
            stopAutoPlay();
            let prevIndex = (currentIndex - 1 + slides.length) % slides.length;
            showSlide(prevIndex);
            startAutoPlay();
        });
        
        nextButton.addEventListener('click', function(e) {
            e.preventDefault();
            stopAutoPlay();
            nextSlide();
            startAutoPlay();
        });
    }
    
    // Add event listeners for indicator clicks
    indicators.forEach((indicator, index) => {
        indicator.addEventListener('click', function() {
            stopAutoPlay();
            showSlide(index);
            startAutoPlay();
        });
    });
    
    // Pause on hover
    carousel.addEventListener('mouseenter', stopAutoPlay);
    carousel.addEventListener('mouseleave', startAutoPlay);
});