// Аяксовая корзина
jQuery('form.variants').live('submit', function(e) {
	e.preventDefault();
	button = jQuery(this).find('input[type="submit"]');
	if(jQuery(this).find('input[name=variant]:checked').size()>0)
		variant = jQuery(this).find('input[name=variant]:checked').val();
	if(jQuery(this).find('select[name=variant]').size()>0)
		variant = jQuery(this).find('select').val();
	jQuery.ajax({
		url: "ajax/cart.php",
		data: {variant: variant,amount: jQuery(this).find('input[name="amount"]').val()},
		dataType: 'json',
		success: function(data){
			jQuery('#cart_informer').html(data);
      jQuery('#shoppingcart').html(data);
      if(jQuery(document).scrollTop() > 150)
       jQuery("#shoppingcart .shopping_cart_mini").fadeIn(500, "linear");
       else
       jQuery("#cart_informer .shopping_cart_mini").fadeIn(500, "linear");
			if(button.attr('data-result-text'))
				button.val(button.attr('data-result-text'));
		}
	});
	var o1 = jQuery(this).offset();
	var o2 = jQuery('#cart_informer').offset();
	var dx = o1.left - o2.left;
	var dy = o1.top - o2.top;
	var distance = Math.sqrt(dx * dx + dy * dy);
	jQuery(this).closest('.product-box').find('.product-image img').effect("transfer", { to: jQuery("#cart_informer"), className: "transfer_class" }, distance);	
	jQuery('.transfer_class').html(jQuery(this).closest('.product-box').find('.product-image').html());
	jQuery('.transfer_class').find('img').css('height', '100%');
	return false;
});



// Аяксовая корзина
jQuery('a[href*="cart?variant"]').live('click', function(e) {
	e.preventDefault();
	//variant_id = jQuery(this).attr('id');
	
	href = jQuery(this).attr('href');
	pattern = /\/?cart\?variant=(\d+)$/;
	variant_id = pattern.exec(href)[1];
	
	link = jQuery(this);
	jQuery.ajax({
		url: "ajax/cart.php",
		data: {variant: variant_id},
		dataType: 'json',
		success: function(data){
			jQuery('#cart_informer').html(data);
			jQuery('#shoppingcart').html(data);
      if(jQuery(document).scrollTop() > 150)
       jQuery("#shoppingcart .shopping_cart_mini").fadeIn(500, "linear");
       else
       jQuery("#cart_informer .shopping_cart_mini").fadeIn(500, "linear");
		}
	});

	var o1 = jQuery(this).offset();
	var o2 = jQuery('#cart_informer').offset();
	var dx = o1.left - o2.left;
	var dy = o1.top - o2.top;
	var distance = Math.sqrt(dx * dx + dy * dy);

	jQuery(this).closest('.prod').find('.product-image-wrapper img').effect("transfer", { to: jQuery("#cart_informer"), className: "transfer_class" }, distance);	
	jQuery('.transfer_class').html(jQuery(this).closest('.product').find('.product-image-wrapper').html());
	jQuery('.transfer_class').find('img').css('height', '100%');
	return false;
});
