/* ==== FG-ZOOM-SYNC 2026-07-07 (Claude): il link zoom/lightbox segue sempre l'immagine visibile. Additivo, rimuovibile. ==== */
jQuery(function($){
function fgZoomSync(){
$('.product-images a, .woocommerce-product-gallery__image a').each(function(){
var img=this.querySelector('img'); if(!img)return;
var u=img.currentSrc||img.src; if(!u||u.indexOf('data:')===0)return;
u=u.replace(/-\d+x\d+(\.[a-z]{3,4})$/i,'$1');
if(this.href!==u){
this.href=u;
var fo=this.getAttribute('data-fresco-options');
if(fo)this.setAttribute('data-fresco-options',fo.replace(/thumbnail:\s*'[^']*'/,"thumbnail:'"+u+"'"));
}
var wrap=this.closest('.product-images, .woocommerce-product-gallery__image, li, figure')||this.parentNode;
var fly=wrap?wrap.querySelector('.easyzoom-flyout img'):null;
if(fly&&fly.src!==u)fly.src=u;
});
}
$(document.body).on('found_variation show_variation woocommerce_variation_has_changed',function(){setTimeout(fgZoomSync,120);setTimeout(fgZoomSync,900);});
$(document).on('change','form.variations_form select',function(){setTimeout(fgZoomSync,150);setTimeout(fgZoomSync,1000);});
$(document).on('mousedown touchstart','.product-images a, .woocommerce-product-gallery__image a',fgZoomSync);
});
/* ==== fine FG-ZOOM-SYNC ==== */