$(document).ready(function () {

    $('.add_to_cart_cat').hover(function(){
        $(this).parent().prev().css('textDecoration', 'underline').prev().css('textDecoration', 'underline');
    }, function(){
        $(this).parent().prev().css('textDecoration', 'none').prev().css('textDecoration', 'none');
    });

	$('#add_to_cart').removeAttr('onclick');
	$('.add_to_cart_cat').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();
				});		
			}			
		});			
	});	
	
	$('.add_to_cart_cat').click(function () {
		var param = $(this).parent();
		$.ajax({
			type: 'post',
			url: 'index.php?route=module/cart/callback',
			dataType: 'html',
			data: $(param).children(':input'),
			success: function (html) {
			$('#module_cart .middle').html(html);
		},	
		complete: function () {
			var product_id = param.children("input[name='product_id']").val();
			var image1 = $('#'+product_id);
			var image = $('#'+product_id).offset();
			var cart  = $('#module_cart').offset();
			
			image1.before('<img src="' + image1.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();
			});		
		}			
		});			
	});			
});
