var redirect = false;

shoppingcart.bindProductForm = function() {
    var cart = this;
    $(".product_form").submit(function(event) {
        event.preventDefault();
        redirect = true;
        var count = 1;
        if ($(this).find('.quantity').length != 0) {
            count = EB_parseInt($(this).find('.quantity').val());
            if (count == 0) count = 1;
        }
        cart.addOrRemoveProduct($(this).find('.product_id').val(), count);
    });
}

shoppingcart.addOrRemoveProductCallback = function(status, data) {
    if (status) {
        if (redirect)
        {
            location.href = '/checkout';
            redirect = false;
        }
        else
        {
            this.refresh('shoppingcart_shoppingcart', { shoppingcart_product_update_id: data.product_id }, function() {
                $('.marked').each(function() {
                    flash_background($(this), 'gray');
                });
            });            
        }
    } else {
        location.href = '/products/go/' + data.product_id;
    }
        }
        
/* Sätt CSS-klass på den nuvarande sidan i huvudmenyn */
$(function() {
    $('a[href=\/' + location.pathname.split('/')[1] + ']').addClass('current');
    $('a[href=\/' + location.pathname.split('/')[1] + ']').parent().addClass('current');
    $('a[href=\/' + location.pathname.split('/')[1] + ']').parent().parent().addClass('current');
});
