let currentSlide = 0;
let interval;
// Create navigation dots
slides.forEach((_, index) => {
const dot = document.createElement('div');
dot.classList.add('testimonial-dot');
if (index === 0) dot.classList.add('active');
dot.addEventListener('click', () => goToSlide(index));
nav.appendChild(dot);
});
function updateSlides() {
slides.forEach((slide, index) => {
slide.classList.toggle('active', index === currentSlide);
track.style.transform = `translateX(-${currentSlide * 100}%)`;
});
document.querySelectorAll('.testimonial-dot').forEach((dot, index) => {
dot.classList.toggle('active', index === currentSlide);
});
}
function goToSlide(index) {
currentSlide = index;
if (currentSlide < 0) currentSlide = slides.length - 1;
if (currentSlide >= slides.length) currentSlide = 0;
updateSlides();
resetInterval();
}
function resetInterval() {
clearInterval(interval);
interval = setInterval(() => {
goToSlide(currentSlide + 1);
}, 5000);
}
prevBtn.addEventListener('click', () => goToSlide(currentSlide - 1));
nextBtn.addEventListener('click', () => goToSlide(currentSlide + 1));
// Start auto-rotation
resetInterval();
// Pause on hover
track.addEventListener('mouseenter', () => clearInterval(interval));
track.addEventListener('mouseleave', resetInterval);
});