Smooth Gallery – product variants change foto

+ COLOR DIV (sita naudoti)

jQuery(document).ready(function() {
    "use strict";

    $(document).bind("change", '#variant_photo_url', function() {
        console.log("variant_photo_url changed");
        runInterval(5, 500)
    });
	
    $(document).bind("click", '.color_select_item_background', function() {
        console.log("variant_photo_url changed");
        runInterval(5, 500)
    });

	
	
	function runInterval(finish, timeout){
		var run=1
		let intervalId = setInterval(function(){ 
			
			update_variant_photo()
			
			if(run > finish - 1){
				update_variant_or_product_photo()
			}			
			if(run > finish){
				update_variant_or_product_photo()
			}
			
			if(run > finish){
				window.clearInterval(intervalId)
			}
			
			run++
		}, timeout);
	}

    function update_variant_photo(){

        const variant_photo_url = $('#variant_photo_url').val()
        console.log(variant_photo_url);

        if(variant_photo_url !== ""){
            console.log("variant_photo_url no empty");
			update_photo(variant_photo_url)
        }
    }

    function update_variant_or_product_photo(){
        const product_photo_url = $('#product_photo_url').val()
        const variant_photo_url = $('#variant_photo_url').val()

        if(variant_photo_url !== ""){
			update_photo(variant_photo_url)
        }
        else{
			update_photo(product_photo_url)
        }
    }
	
	function update_photo(photo_url){
		//$('.product_smooth_gallery .sp-current-big').attr('href', photo_url)
		//$('.product_smooth_gallery .sp-current-big img').attr('src', photo_url)
		
		$('.product_smooth_gallery .sp-large a').attr('href', photo_url)
		$('.product_smooth_gallery .sp-large a img').attr('src', photo_url)
		
	}
})

shopwise autoresize gallery (nereikalingas, smooth gallery atlieka sia func)

$( document ).ready(function() {

	$('.product_gallery_item').on('click', function(){
		setTimeout(function(){
			const $img_box = $('.product_img_box')
			const img_box_height = parseInt( $img_box.css('height') ) - 16
			const img_box_width = parseInt( $img_box.css('width') ) - 16

			$('.zoomContainer').css('width', img_box_width)
			$('.zoomContainer').css('height', img_box_height)

			$('.zoomWindow').css('width', img_box_width)
			$('.zoomWindow').css('height', img_box_height)

		}, 200)
	})
	
})