jQuery(function($){let c=1;$('.c8-griditem').each(function(){$(this).addClass('lightbox-open'+c);c++;});c=1;$('.c8-lightbox .lightbox-item').each(function(){$(this).addClass('lightbox-open'+c);c++;});function clearUrlHash(){var uri=window.location.toString();if(uri.indexOf('#')>0){let cleanUri=uri.substring(0,uri.indexOf("#"));window.history.replaceState({},document.title,cleanUri);}}
$('.c8-griditem div, .c8-griditem .c8-gridtext').click(function(){var lightbox=$(this).parent().attr("class").match(/lightbox-open[\w-]*\b/);window.location.hash=`#${$(this).parent().data('mt')}`;$('.c8-lightbox').fadeIn("slow",function(){});$('.c8-lightbox .lightbox-item').hide();$('.lightbox-container .'+lightbox[0]).addClass('open');$('.lightbox-container .'+lightbox[0]).fadeIn("slow",function(){});$('.b-lightbox').scrollTop(0);});$('.c8-lightbox-close').click(function(){clearUrlHash();$('.c8-lightbox .lightbox-item').removeClass('open');$('.c8-lightbox').fadeOut("slow",function(){});$('.c8-lightbox .lightbox-item').fadeOut("slow",function(){});});$(".c8-lightbox").click(function(e){if(e.target!==e.currentTarget)return;$('.c8-lightbox-close').click();});$(document).on('keydown',function(event){if(event.key=="Escape"){$('.c8-lightbox-close').click();}});window.addEventListener("keydown",function(event){if($('.c8-lightbox .lightbox-item.open').length>0){if(event.defaultPrevented){return;}
let lightboxPos=$('.c8-lightbox .lightbox-item.open').attr("class").match(/\d+/);var position=parseInt(lightboxPos[0]);switch(event.key){case "Left":case "ArrowLeft":position=position-1;if(position<1){position=$('.c8-lightbox .lightbox-item').length;}
clearUrlHash();$('.c8-lightbox-close').click();setTimeout(function(){$('.c8-lightbox').fadeIn("slow",function(){});$('.c8-lightbox .lightbox-item').hide();$('.lightbox-container .lightbox-open'+position).addClass('open');$('.lightbox-container .lightbox-open'+position).fadeIn("slow",function(){});window.location.hash=`#${$('.lightbox-container .lightbox-open'+position).data('mt')}`;$('.c8-lightbox').scrollTop(0);},200);break;case "Right":case "ArrowRight":position=position+1;if(position>$('.lightbox-item').length){position=1;}
clearUrlHash();$('.c8-lightbox-close').click();setTimeout(function(){$('.c8-lightbox').fadeIn("slow",function(){});$('.c8-lightbox .lightbox-item').hide();$('.lightbox-container .lightbox-open'+position).addClass('open');$('.lightbox-container .lightbox-open'+position).fadeIn("slow",function(){});window.location.hash=`#${$('.lightbox-container .lightbox-open'+position).data('mt')}`;$('.c8-lightbox').scrollTop(0);},200);break;default:return;}
event.preventDefault();}},true);let hash=window.location.hash.toString().replace('#','');if(hash){let $target=$(`[data-mt=${hash}]`);if($target){let lightbox=$target.attr("class").match(/lightbox-open[\w-]*\b/);$('.c8-lightbox').fadeIn("slow",function(){});$('.c8-lightbox .lightbox-item').hide();$('.lightbox-container .'+lightbox[0]).fadeIn("slow",function(){$([document.documentElement,document.body]).animate({scrollTop:$(`.c8-griditem[data-mt=${hash}]`).offset().top-86},250);});}}});