$('form.tocart button.plus').live('click', function() {
    count = $('input[name=count]', $(this).parent()).val();
    count = count * 1 + 1;
    $('input[name=count]', $(this).parent()).val(count);
    return false;
});

$('form.tocart button.minus').live('click', function() {
    count = $('input[name=count]', $(this).parent()).val();
    count = count * 1;
    if (count > 1) {
        count = count - 1;
        $('input[name=count]', $(this).parent()).val(count);
    }
    return false;
});

$('form.tocart').live('submit', function() {
    var btn = $(this);
    $.ajax({
       type: 'POST',
       url: $(this).attr('action'),
       data: $(this).serializeArray(),
       dataType: 'JSON',
       success: function(result) {
            if (result.result) {
                // обновить виджет с текущим кол-вом
                $('#cart').html(result.cart);
                
                // вывести окно
                $('div.popup-info').remove();
                p = $(btn).offset();
                var infoPopup = $('<div>').attr('class', 'popup popup-info').html('<div class="inner">' + result.text + '</div>').appendTo('body');
                infoPopup.css('top', p.top).show();
                setTimeout(function() {infoPopup.fadeOut(function() {$(this).remove()})}, 1500);
            }
       }
    });
    return false;
});

