$(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 + 'px',
					left : cart.left + 'px',
					opacity : 0.0,
					width : $('#module_cart').width(),  
					height : $('#module_cart').height()
				};		
	
				$('#temp').animate(params, 'slow', false, function () {
					$('#temp').remove();
				});		
			}			
		});			
	});		
	
	$('#check_out_now').removeAttr('onclick');
	$('#check_out_now').click(function () {
		 $.ajax({
            type: 'post',
            url: 'index.php?route=module/cart/clear',
            dataType: 'html',
            success: function (html) {
				$.ajax({
					type: 'post',
					url: 'index.php?route=module/cart/callback',
					dataType: 'html',
					data: $('#product :input'),
					complete: function () {
						window.location = "/index.php?route=checkout/shipping";
					}			
				});
            },
        });			
	});
});

function main_page_cart(product_id) {
	$.ajax({
		type: 'post',
		url: 'index.php?route=module/cart/callback',
		dataType: 'html',
		data: $('#product_' + product_id + ' :input'),
		success: function (html) {
			$('#module_cart .middle').html(html);
		},	
		complete: function () {
			var image = $('#image').offset();
				var cart  = $('#module_cart').offset();
	
				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();
				});	
		}			
	});
}

function main_page_checkout(product_id) {
	$.ajax({
        type: 'post',
        url: 'index.php?route=module/cart/clear',
        dataType: 'html',
        success: function (html) {
			$.ajax({
				type: 'post',
				url: 'index.php?route=module/cart/callback',
				dataType: 'html',
				data: $('#product_' + product_id + ' :input'),
				complete: function () {
					window.location = "/index.php?route=checkout/shipping";
				}			
			});
        },
    });
}

