function addToCartButtons(){
    if (jQuery(".btn_add_to_cart") || jQuery(".btn_add_to_cart_lg")) {
        var cart = jQuery('#perpetual_cart');
        jQuery(".btn_add_to_cart, .btn_add_to_cart_lg").click(function() {
            jQuery('#perpetual_cart #cartHeader strong').addClass('loading');
            if (jQuery(this).hasClass('btn_add_to_cart_lg')) {
                var params = '';

                jQuery('#product_addtocart_form input:not(":radio"), #product_addtocart_form select').each(function(i) {
                       if (i != 0) { params += '&' }
                       params += this.name + '=' + this.value;
                });
                jQuery('#product_addtocart_form input:is(":radio")').each(function(i) {
                    if (jQuery(this).is(':checked')){
                        if (i != 0) { params += '&' }
                        params += this.name + '=' + this.value;
                    }
                });
            }
            else {
                params = 'product=' + this.id + '&qty=1';
            }
            var result = jQuery.getJSON("/ajaxCart.php", params, function(data, textStatus){
                if (textStatus == "error"){
                    jQuery('#perpetual_cart #cartHeader strong').removeClass('loading');
                    alert("There was an error adding this item to your cart.  Please call customer service for assistance.", "Error");
                    return;
                }
                if (data.result == "error"){
                    jQuery('#perpetual_cart #cartHeader strong').removeClass('loading');
                    alert("Sorry, an error occurred while adding the item to your cart.  The error was: '" + data.message + "'");
                    return;
                }
                jQuery.ajax({
                    type: "GET",
                    url: "/updateCart.php",
                    dataType: 'html',
                    success: function(msg){
                        cart.html(msg);
                        Enterprise.TopCart.showCart(7);
                    }
                });
            });
            location.href = '#logo';
            return false;
        });
    }
    if (jQuery('#perpetual_cart .btn-remove')) {
        jQuery("#perpetual_cart .btn-remove").each(function() {
            jQuery(this).click(function(){
                jQuery('#perpetual_cart #cartHeader strong').addClass('loading');
                var removeLink = jQuery(this).attr("href");
                jQuery.ajax({
                    type: "GET",
                    url: removeLink,
                    success: function() {
                        jQuery.ajax({
                            type: "GET",
                            url: "/updateCart.php",
                            dataType: 'html',
                            success: function(msg){
                                cart.html(msg);
                            }
                        });
                    }
                });
                return false;
            });
        });
    }
}
jQuery(document).ready(function() {
    addToCartButtons();
});