$(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) {
				if(html=='false'){
					top.location.href='index.php?route=account/login';
				}else{
					$('#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();
				});		
			}			
		});			
	});			
	
	$('.add_to_cart').click(function () {
//		alert($(this).attr('rel'));
		var book_id=$(this).attr('rel');
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: {"product_id":book_id,"quantity":1},
			success: function (html) {
				if(html=='false'){
					top.location.href='index.php?route=account/login';
				}else{
					$('#module_cart .middle').html(html);
				}
			},	
			complete: function () {
				//alert(book_id);
				var image = $('#book_image-'+book_id).offset();
				var cart  = $('#module_cart').offset();
	
				$('#book_image-'+book_id).before('<img src="' + $('#book_image-'+book_id).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();
				});		
			}			
			
			
		});			
	});			
	
});
