jQuery(document).ready(function($) {
	$('.quickview').click(function() {
		var $thisbutton = $(this);
		var prodid = $thisbutton.data('prodid');
		var magnificPopup;
		$.ajax({
			url: woocommerce_params.ajax_url,
			method: 'POST',
			data: {
				'action': 'et_product_quick_view',
				'prodid': prodid
			},
			dataType: 'html',
			beforeSend: function() {
				$thisbutton.parent().parent().addClass('loading');
				$thisbutton.after('<div id="floatingCirclesG"><div class="f_circleG" id="frotateG_01"></div><div class="f_circleG" id="frotateG_02"></div><div class="f_circleG" id="frotateG_03"></div><div class="f_circleG" id="frotateG_04"></div><div class="f_circleG" id="frotateG_05"></div><div class="f_circleG" id="frotateG_06"></div><div class="f_circleG" id="frotateG_07"></div><div class="f_circleG" id="frotateG_08"></div></div>');
			},
			complete: function() {
				$thisbutton.parent().find('#floatingCirclesG').remove();
				$thisbutton.parent().parent().removeClass('loading');
			},
			success: function(response){

				$.magnificPopup.open({
					items: { src: '<div class="quick-view-popup mfp-with-anim"><div class="doubled-border">' + response + '</div></div>' },
					type: 'inline',
					removalDelay: 500, //delay removal by X to allow out-animation
					callbacks: {
						beforeOpen: function() {
							this.st.mainClass = 'mfp-zoom-in-to-left-out';
						}
					}
				}, 0);

				$(function() {
					$('.variations_form').wc_variation_form();
					$('.variations_form .variations select').change();
				});
				$('.images').addClass('shown');
			},
			error: function() {
				$.magnificPopup.open({
					items: {
						src: '<div class="quick-view-popup mfp-with-anim"><div class="doubled-border">Error with AJAX request</div></div>'
					},
					type: 'inline',
					removalDelay: 500, //delay removal by X to allow out-animation
					callbacks: {
						beforeOpen: function() {
							this.st.mainClass = 'mfp-zoom-in-to-left-out';
						}
					}
				}, 0);
			}
		});

	});
});