/* jQuery Shopping Cart by Oscommerce Ready
 *
 * Published under GNU License 
 * 
 */
$(document).ready(function() {

	$('#cart_quantity').live('submit', function() {
	
		$('#button_submit').attr('disabled', 'disabled');
		$('#button_submit2').attr('disabled', 'disabled');
		
		// Run the effect 
		// Partial code from :  http://webresourcesdepot.com/wp-content/uploads/file/jbasket/fly-to-basket/
		var productX = $('#cart-image').offset().left;
		var productY = $('#cart-image').offset().top;
 
		var basketX = $('#ajax_cart').offset().left;
		var basketY = $('#ajax_cart').offset().top + 10;

		var gotoX = basketX - productX ;
		var gotoY = basketY - productY  ;

		var newImageWidth = $('#cart-image').width() / 2;
		var newImageHeight = $('#cart-image').height() / 2;
    
		$('#wrapper').html('');

		$('#cart-image').clone()
        .prependTo('#wrapper')
		.css({'position' : 'absolute','z-index':9999, 'border' : '1px dashed black'})
        .animate({opacity: 0.6})
        .animate({opacity: 0.0, marginLeft: gotoX, marginTop: gotoY, width: newImageWidth, height: newImageHeight}, 1200,
        function() {
						
			var datas_form = $('#cart_quantity').serializeArray();
			$.ajax({
				url:'ajax_add_cart.php',
				data: datas_form,
				type: 'POST',
				async:false,
				success: function(data) {
					var datas = data.split("|");
					setTimeout(function() {

						$('#content_products').html(datas[0]);					
						$('#content_total').html(datas[1]);
						$('#checkout_button').html(datas[3]);
						$('#fila_' + datas[2]).fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast");
						$('#content_total').fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast").fadeOut("fast").fadeIn("fast");
						
					}, 1300);
				}
			});
			
		  // Updating header cart (number of items)
		  //
          $.ajax({
              type: 'POST',
			  url: encodeURI($('form[name=boxcart_count]').attr('action')) + '?show_items=1&ajax=1',
			  data: $('form[name=boxcart_count]').serialize(),			  			  
              success: function(data) {
			  	  var datas = data.split("|");
				  setTimeout(function() {
				  
					$('#boxcart-items').html(datas[0]);
					$('#checkout_header').html(datas[1]);
					
					}, 1300);					
					
                  }
              });			
			
			$('#button_submit').attr('disabled', '');
			$('#button_submit2').attr('disabled', '');
			$(this).remove();
        });			
			return false;
		});

});
/* EO jQuery Shopping Cart */

