$(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();
				});		
			}			
		});			
	});			
});
function NewbuyProduct(id)
{
	var ButtonTxt = document.getElementById('add_to_cart'+id);
	ButtonTxt.innerHTML = '<span><img width="18" height="15" src="pics/ajax_load.gif">Добавляется...</span>';
	var TextFieldName = 'ProductOpt'+id; 
	var ProductOptions = document.getElementById(TextFieldName).value;
	var appendurl  = "" ; 
	if(ProductOptions != 0)
	{
		var Optionvalues = new Array();
		Optionvalues = ProductOptions.split(",");
		for (var i = 0; i < Optionvalues.length; i++)
		{				
			if(Optionvalues[i] == '0'){}
			else
			{
			   var OptionvalueLabel = "option["+Optionvalues[i]+"]";
			   var ValueProductOptions = document.getElementById(OptionvalueLabel).value;
			   appendurl += "&option["+Optionvalues[i]+"]="+ValueProductOptions;
			}
		}
	}

	$.ajax({
            type: 'post',
            url: 'index.php?route=module/cart/callback',
            dataType: 'html',
            data: 'product_id='+id+'&quantity=1'+appendurl,
            success: function (html) {
                $('#module_cart .middle').html(html);
            },    
            
        complete: function () 
	{
                var image = $('#image'+id).offset();
                var cart  = $('#module_cart').offset();
    
                $('#image'+id).before('<img src="' + $('#image'+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(),  
                    heigth : $('#module_cart').height()
                };        
    
                $('#temp').animate(params, 'slow', false, function () {
                    $('#temp').remove();
                });        
               	ButtonTxt.innerHTML = '<span>В корзину</span>';
         }    
  });  				
}
