jQuery(function($) {
    var cartInfo = $('#cart-info');
    var pulse = $('#pulse');
    $('input.product-to-cart-submit').live('click', function() {
        var $this = $(this);
        var form = $this.closest('form');
        var data = form.serialize() + '&' + $this.attr('name') + '=' + 'on';
        var product = $this.closest('.product');
        $.ajax({
            type: 'POST',
            url: form.attr('action'),
            data: data,
            success: function(response) {
                pulse.show()
                     .offset(product.offset())
                     .width(product.outerWidth()-6)
                     .height(product.height()-6)
                     .animate({opacity: 1.0})
                     .animate({opacity: 0.0},
                              {complete: function() {
                                   var toCartIcon = $('#to-cart .icon');
                                   console.debug(toCartIcon.offset());
                                   console.debug(toCartIcon.outerWidth());
                                   console.debug(toCartIcon.outerHeight());
                                  pulse.offset(toCartIcon.offset())
                                       .width(toCartIcon.outerWidth())
                                       .height(toCartIcon.outerHeight())
                                       .animate({opacity: 1.0})
                                       .animate({opacity: 0.0},
                                                {complete: function() {
                                                    pulse.hide();
                                                }});
                              }});
                cartInfo.html(response);
            }});
        return false;
    });
});
