const multiLightbox = function () {
	'use strict';

	const selectorParts = ['.lightbox', 'a[href*=".jpg"]', 'a[href*=".jpeg"]', 'a[href*=".png"]', 'a[href*=".gif"]', 'a[href*=".JPG"]', 'a[href*=".JPEG"]', 'a[href*=".PNG"]', 'a[href*=".GIF"]'];
	selectorParts.forEach(function(part, index) {
		selectorParts[index] = part + ':not(.action):not(.thumbnail-overlay-link):not(.thumbnail-link):not(.title-image-link):not(.project-lightbox):not(.mb-gallery-lightbox)';
	});

	const lightboxLinks = document.querySelectorAll(selectorParts.join(','));
	lightboxLinks.forEach(function (link) {
		link.addEventListener('click', function(event) {
			event.preventDefault();

			const elements = [{
				href: link.getAttribute('href')
			}];
			const basicOptions = {
				elements: elements,
				autoplayVideos: false,
				touchNavigation: false,
				autoplayVideos: true,
			}

			const basicLightbox = GLightbox(basicOptions);
			basicLightbox.open();
		})
	});
}

window.addEventListener('load', multiLightbox);
document.addEventListener('related-post-loaded', multiLightbox);
