﻿var addToCart = undefined;

$(document).ready(function() {
   
    var updateCart = function(pid){
        button = '<div class="avl"><a href="'+__WWWHOST+'cart.php">В корзине</a></div>';
        $('#buy_'+pid).replaceWith(button);
 /*button.animate({'width': '78','height' : '25','paddingTop' : '0','paddingRight' : '0','paddingLeft' : '2px',
 'paddingBottom' : '0','top' : '-0%','right' : '-6px','fontSize' : '10px','lineHeight' : '10px'},200);*/
  
        ans = jQuery.ajax({
            type: 'GET',
            url: __WWWHOST+'one.php',
            data: {
                __one_a: 'Basket',
                __one_b: 'Basket'
            },
            dataType: 'html',
            error: function(r,s,e) { alert(r.responseText); alert('[AJAX Error0] '+e); },
            success: function(data) {
                $('#basket_container').html(data);
				$('#overlay').remove();
            }
        });
    };
   
    addToCart = function(pid,pcount) {
		overlay();
        //$('#alert').hide();
        ans = jQuery.ajax({
			type: "GET",
			url: __WWWHOST+'action.php',
			data: {
				mode: 'ajax',
				action: 'Cart',
				Cart_method: 'add',
				Cart_id: pid,
                Cart_count: pcount
			},
			dataType: 'xml',
			error: function(r,s,e) { alert(r.responseText); alert('[AJAX Error0] '+e); },
			success: function(xml,s,r) { 				
				updateCart(pid);
			}
		});
	};       
});
