// alert('test');
$(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_price').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(),  
					// heigth : $('#module_cart').height()
				// };		
	
				// $('#temp').animate(params, 'slow', false, function () {
					// $('#temp').remove();
				// });		
			}			
		});			
	});			
});

	window.alertTimerId = 0;
	function addToCart(product_id) {
		clearTimeout ( window.alertTimerId );
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: 'product_id=' + product_id + '&quantity=1&oscwd=true',
			success: function (html) {
				move_popup('div#container','div#addToCartContainer');
				html = html.split('||');
				var bookName = html[0];
				var cartTotal = html[1];
				$('#module_cart_price').html(cartTotal);
				$('span#addToCartContainer_book_name').html(bookName);
				// $('div#addToCartContainer').show(function(){
					// $('div#addToCartContainer').fadeToggle('slow','linear');
					// window.alertTimerId = setTimeout ( "fadeaddToCartContainer()", 15000 );
				// });
				$('div#addToCartContainer').fadeIn('slow','linear');
				window.alertTimerId = setTimeout ( "fadeaddToCartContainer()", 15000 );
				
			},	
			complete: function () {
				// $('div#addToCartContainer').fadeToggle();
				// 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(),  
					// heigth : $('#module_cart').height()
				// };		
	
				// $('#temp').animate(params, 'slow', false, function () {
					// $('#temp').remove();
				// });		
			}
		});
	}

	function removeCart(key) {
		clearTimeout ( window.alertTimerId );
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: 'remove=' + key,
			success: function (html) {
				move_popup('div#container','div#addToCartContainer');
				$('#module_cart_price').html(html);
				$('div#addToCartContainer').show().fadeToggle('slow','linear');
				window.alertTimerId = setTimeout ( "fadeaddToCartContainer()", 5000 );
			},	
			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(),  
					// heigth : $('#module_cart').height()
				// };		
	
				// $('#temp').animate(params, 'slow', false, function () {
					// $('#temp').remove();
				// });		
			}
		});
	}
