$(document).ready(function () {
							
	$('#add_to_cart,.add_to_cart').removeAttr('onclick').removeAttr('href');
	
	$('.hide_js').hide();
	$('.show_js').removeClass('show_js');

	$('#add_to_cart').click(function () {
		var basket_discounts = $('#module_cart #basket_discounts');							  
		var basket_qty = $(this).siblings('input');
		var stock_qty = $(this).parents('form').siblings('table').find('.stock');
		if(basket_qty.val() > Number(stock_qty.html()))
			{
				alert('You have added more products than the number available. Please try again.');
				return false;
			}
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'json',
			data: $('#product :input'),
			success: function (html) {
				$('#module_cart .middle').html(html.output).append(basket_discounts);
				$('#module_cart h2 span').html('('+html.weight+')');
			},	
			complete: function () {
				var image = $('#image').offset();
				var cart  = $('#module_cart').offset();
	
				$('#header').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();
				});		
				
				stock_qty.html(stock_qty.html()-basket_qty.val());
			}			
		});			
	});			
	
	$('.add_to_cart').click(function () {
		var basket_discounts = $('#module_cart #basket_discounts');							  
		var basket_qty = $(this).siblings('.quantity');
		var stock_qty = $(this).parents('td').find('.stock');
		if(basket_qty.val() > Number(stock_qty.html()))
			{
				alert('You have added more products than the number available. Please try again.');
				return false;
			}
		$itemimg = $(this).parents('td').find('.item_image');
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'json',
			data: $(this).parent().find('input'),
			success: function (html) {
				$('#module_cart .middle').html(html.output).append(basket_discounts);
				$('#module_cart h2 span').html('('+html.weight+')');
			},	
			complete: function () {
				var image = $itemimg.offset();
				var cart  = $('#module_cart').offset();
	
				$('#header').before('<img src="' + $($itemimg).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();
				});	
				
				stock_qty.html(stock_qty.html()-basket_qty.val());
			}			
		});			
	});			
});
