$(document).ready(function () {
	$('#add_to_cart').removeAttr('onclick');

	$('#add_to_cart').click(function () {
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: $('#product :input'),
			success: function (html) {
				$('#module_cart .middle').html(html);
			},	
			complete: function () {
				var image = $('#image').offset();
				var cart  = $('#module_cart').offset();
	
				$('#image').before('<img src="' + $('#image').attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
	
				params = {
					top : cart.top + 50 + 'px',
					left : cart.left + 'px',
					opacity : 100.100,
					width : 130,
					height : 130
				};		
	
				$('#temp').animate(params, 'slow', false, function () {
					$('#temp').remove();
				});		
			}			
		});			
	});			

   $('.add_to_cart').each(function(){
       var _pa = $(this);
       var _pid = _pa.attr('rel');
       _pa.click(function () {
      $.ajax({
         type: 'post',
         url: 'index.php?route=module/cart/callback',
         dataType: 'html',
         data: $('#product_'+_pid+' :input'),
         success: function (html) {
            $('#module_cart .middle').html(html);
         },   
         complete: function () {
            var image = $('#image_'+_pid).offset();
            var cart  = $('#module_cart').offset();
   
            $('#image_'+_pid).before('<img src="' + $('#image_'+_pid).attr('src') + '" id="temp_'+_pid+'" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');
   
            params = {
               top : image.top + 80 + 'px',
               left : cart.left -180 + 'px',
               opacity : 100.100,
               width : 50,
               heigth : 50
            };
            $('#temp_'+_pid).animate(params, 'slow', false, function () {
               $('#temp_'+_pid).remove();
            });
         }
      });
       });
   });

});
