jQuery(document).ready(function($){

	$( 'form.variations_form' ).on( 'found_variation', function( event, variation ) {

		var image_magnifier = variation.image_magnifier ? variation.image_magnifier : yith_wcmg_default_zoom;
		var image_src       = variation.image_src ? variation.image_src : yith_wcmg_default_image;

		yith_wcmg_zoom.attr('href', image_magnifier);
		yith_wcmg_image.attr('src', image_src);
		
		if( yith_wcmg.data('yith_magnifier') ) {
			yith_wcmg.yith_magnifier('destroy');
		}

 		yith_wcmg.yith_magnifier(yith_magnifier_options);

	}).on( 'reset_image', function( event ) {
		yith_wcmg_zoom.attr('href', yith_wcmg_default_zoom);
		yith_wcmg_image.attr('src', yith_wcmg_default_image);

		if( yith_wcmg.data('yith_magnifier') ) {
			yith_wcmg.yith_magnifier('destroy');
		}

 		yith_wcmg.yith_magnifier(yith_magnifier_options);
		 		 
	});

	var yith_wcmg = $('.images');
	var yith_wcmg_zoom  = $('.yith_magnifier_zoom');
	var yith_wcmg_image = $('.yith_magnifier_zoom img');
	
	var yith_wcmg_default_zoom = yith_wcmg.find('.yith_magnifier_zoom').attr('href');
	var yith_wcmg_default_image = yith_wcmg.find('.yith_magnifier_zoom img').attr('src');
	
	yith_wcmg.yith_magnifier(yith_magnifier_options);

});
