(function(){const galleryImages=document.querySelectorAll('.tukc-product-gallery-images .woocommerce-product-gallery__image');const thumbs=document.querySelectorAll('.tukc-product-gallery-thumbnail');const thumbsWrap=document.querySelector('.tukc-product-gallery-thumbnails');const navPrev=document.querySelector('.tukc-product-gallery-nav-prev');const navNext=document.querySelector('.tukc-product-gallery-nav-next');if(!galleryImages.length)return;let current=0;let lockScrollY=null;let isRestoring=!1;window.addEventListener('scroll',function(){if(isRestoring||lockScrollY===null)return;isRestoring=!0;window.scrollTo({top:lockScrollY,behavior:'instant'});setTimeout(function(){isRestoring=!1},0)});function navigate(newIndex){lockScrollY=window.scrollY;goTo(newIndex);window.scrollTo({top:lockScrollY,behavior:'instant'});setTimeout(function(){lockScrollY=null},300)}
function goTo(index){if(index===current)return;galleryImages[current].classList.remove('active');if(thumbs[current])thumbs[current].classList.remove('active');galleryImages[index].classList.add('active');if(thumbs[index])thumbs[index].classList.add('active');current=index;gsap.killTweensOf(galleryImages[index]);gsap.fromTo(galleryImages[index],{opacity:0},{opacity:1,duration:0.3})}
if(navNext){navNext.addEventListener('click',function(e){e.preventDefault();navigate((current+1)%galleryImages.length)})}
if(navPrev){navPrev.addEventListener('click',function(e){e.preventDefault();navigate((current-1+galleryImages.length)%galleryImages.length)})}
thumbs.forEach(function(thumb,i){thumb.removeAttribute('href');thumb.addEventListener('click',function(e){e.preventDefault();goTo(i)})});const THUMB_LIMIT=8;if(thumbs.length>THUMB_LIMIT&&window.innerWidth>768){thumbs.forEach(function(thumb,i){if(i>=THUMB_LIMIT)thumb.style.display='none'});const lastVisible=thumbs[THUMB_LIMIT-1];const seeMore=document.createElement('div');seeMore.className='tukc-gallery-see-more';seeMore.innerHTML='<span class="tukc-gallery-see-more-count">+'+(thumbs.length-(THUMB_LIMIT-1))+'</span><span class="tukc-gallery-see-more-label">photos</span>';lastVisible.style.position='relative';lastVisible.appendChild(seeMore);seeMore.addEventListener('click',function(e){e.preventDefault();e.stopPropagation();seeMore.remove();lastVisible.style.position='';thumbs.forEach(function(thumb){thumb.style.display=''});var gallery=document.getElementById('gallery');if(gallery)gallery.style.position='static';window.scrollTo({top:0,behavior:'smooth'})})}})()