document.addEventListener('DOMContentLoaded', () => { const backgroundOverlay = document.getElementById('backgroundOverlay'); const baseUrl = '/img/bg/4/'; const images = ['010111015788.jpg', '0101166506790.jpg', '0101332363820.jpg']; let currentIndex = 0; const changeBackground = () => { const imageUrl = `${baseUrl}${images[currentIndex]}`; const newImage = new Image(); newImage.onload = () => { backgroundOverlay.style.backgroundImage = `url('${imageUrl}')`; setTimeout(() => { backgroundOverlay.classList.add('visible'); }, 100); }; newImage.onerror = () => { backgroundOverlay.style.backgroundImage = `url('https://placehold.co/1920x1080/000000/FFFFFF?text=Zdjęcie+kręgielni')`; setTimeout(() => { backgroundOverlay.classList.add('visible'); }, 100); }; newImage.src = imageUrl; currentIndex = (currentIndex + 1) % images.length; }; changeBackground(); setInterval(() => { backgroundOverlay.classList.remove('visible'); setTimeout(changeBackground, 3000); }, 6000); });