let lightboxImages = []; let currentIndex = -1; // no image selected yet function showLightbox(index) { if (index < 0 || index >= lightboxImages.length) return; const lightbox = document.getElementById('lightbox'); const lightboxImg = document.getElementById('lightbox-img'); lightboxImg.src = lightboxImages[index]; currentIndex = index; lightbox.style.display = 'flex'; } function closeLightbox() { document.getElementById('lightbox').style.display = 'none'; document.getElementById('lightbox-img').src = ''; currentIndex = -1; } function nextLightbox() { if (currentIndex === -1) return; let next = (currentIndex + 1) % lightboxImages.length; showLightbox(next); } function prevLightbox() { if (currentIndex === -1) return; let prev = (currentIndex - 1 + lightboxImages.length) % lightboxImages.length; showLightbox(prev); } document.addEventListener('DOMContentLoaded', function () { const links = document.querySelectorAll('.actor-photo-content a'); const lightbox = document.getElementById('lightbox'); const lightboxImg = document.getElementById('lightbox-img'); lightboxImages = Array.from(links).map(link => link.getAttribute('href')); links.forEach((link, index) => { link.addEventListener('click', function (e) { e.preventDefault(); showLightbox(index); }); }); lightbox.addEventListener('click', function (e) { if (e.target === lightbox) { closeLightbox(); } }); document.addEventListener('keydown', function (e) { const lightboxVisible = document.getElementById('lightbox').style.display === 'flex'; if (!lightboxVisible) return; if (e.key === 'Escape') closeLightbox(); if (e.key === 'ArrowRight') nextLightbox(); if (e.key === 'ArrowLeft') prevLightbox(); }); });