$(function(){
    cartCalculation();
});

function cartCalculation() {
        if(typeof(prices) != 'undefined') {
        var total_price = 0;
        $('table.winkelmandje tr').each(function() {
            
            // PRIJS OBJECT VOOR DIT PRODUCT
            var price_obj   = prices[this.id];
            
            // AANTAL OPHALEN
            var selector    = '#'+this.id+' select';
            var amount      = $(selector).val();
            
            // TD WAAR DE PRIJS IN KOMT TE STAAN
            selector        = '#'+this.id+' td.last-child';
            var pricebox    = $(selector);
            
            // ACTIECODE GEBRUIKT?
            selector        = '#'+this.id+' input.actiecode';
            var actiecode   = $(selector);
            
            var price = 0;
            
            if(actiecode.attr('disabled')) {
                price = price_obj.price_action*amount;
            } else {
                price = price_obj.price_regular*amount;
            }
             
            // PRIJS INVULLEN   
            pricebox.html('<span>&euro; '+(price_obj.price_regular*amount).toFixed(2)+'</span><br /> &euro; '+(price_obj.price_action*amount).toFixed(2));
            
            total_price += price;
        });
    
    $('#subtotaal').html('&euro; '+total_price.toFixed(2));
    $('#totaal').html('&euro; '+(total_price+prices.verzendkosten).toFixed(2));
    } 
}
