$(document).ready(function () {

	$('#add_to_cart').removeAttr('onclick');
	
	
	$('a#add_to_cart_a').each( function(index) {
	
		$(this).removeAttr('href');


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

	$('#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 + 'px',
					left : cart.left + 'px',
					opacity : 0.0,
					width : $('#module_cart').width(),  
					height : $('#module_cart').height()
				};		
	
				$('#temp').animate(params, 'slow', false, function () {
					$('#temp').remove();
				});		
			}			
		});			
	});			



});
