;
var currentIndex = 0;
var fotoItems = document.querySelectorAll('.foto-item');
for (var i = 0; i < fotoItems.length; i++) {
fotoItems[i].addEventListener('click', function() {
var index = parseInt(this.getAttribute('data-index'));
abrirLightbox(index);
});
}
function abrirLightbox(index) {
currentIndex = index;
mostrarFoto();
document.getElementById('lightbox-' + uniqueId).classList.add('active');
document.body.style.overflow = 'hidden';
}
function fecharLightbox() {
document.getElementById('lightbox-' + uniqueId).classList.remove('active');
document.body.style.overflow = '';
}
function navegarLightbox(direction) {
currentIndex += direction;
if (currentIndex < 0) {
currentIndex = fotosData.length - 1;
} else if (currentIndex >= fotosData.length) {
currentIndex = 0;
}
mostrarFoto();
}
function mostrarFoto() {
var foto = fotosData[currentIndex];
var imgSrc = 'uploads/albums/fotos/' + foto.imagem;
var titulo = foto.titulo || '';
var descricao = foto.descricao || '';
document.getElementById('lightboxImg-' + uniqueId).src = imgSrc;
document.getElementById('lightboxTitulo-' + uniqueId).textContent = titulo;
document.getElementById('lightboxDescricao-' + uniqueId).textContent = descricao;
document.getElementById('lightboxCounter-' + uniqueId).textContent = (currentIndex + 1) + ' / ' + fotosData.length;
var info = document.querySelector('#lightbox-' + uniqueId + ' .lightbox-info');
if (!titulo && !descricao) {
info.style.display = 'none';
} else {
info.style.display = 'block';
}
}
document.querySelector('#lightbox-' + uniqueId + ' .lightbox-close').addEventListener('click', fecharLightbox);
document.querySelector('#lightbox-' + uniqueId + ' .lightbox-overlay').addEventListener('click', fecharLightbox);
document.querySelector('#lightbox-' + uniqueId + ' .lightbox-prev').addEventListener('click', function() {
navegarLightbox(-1);
});
document.querySelector('#lightbox-' + uniqueId + ' .lightbox-next').addEventListener('click', function() {
navegarLightbox(1);
});
document.addEventListener('keydown', function(e) {
var lightbox = document.getElementById('lightbox-' + uniqueId);
if (lightbox && lightbox.classList.contains('active')) {
if (e.key === 'Escape') {
fecharLightbox();
} else if (e.key === 'ArrowLeft') {
navegarLightbox(-1);
} else if (e.key === 'ArrowRight') {
navegarLightbox(1);
}
}
});
})();