var basket = (function(options)
{
    this.base_url = options.base_url,
    this.add = function(article_nr, callback) {
        var async = true;
        if( callback == null ) async = false;
        $.ajax({
          type: "POST",
          async: async,
          url: this.base_url + "add",
          data: { "article_nr": article_nr },
          dataType: "json",
          success: function(data) {
              if( callback != null ) {
                  callback(article_nr, data);
              }
              console.log(data);
          }
        });       
    },
    this.remove = function(article_nr, callback) {
        var async = true;
        if( callback == null ) async = false;
        $.ajax({
          type: "POST",
          async: async,
          url: this.base_url + "del",
          data: { "article_nr": article_nr },
          dataType: "json",
          success: function(data) {
              if( callback != null ) {
                callback(article_nr, data);
              }
              console.log(data);
          }
        });       
    },
    this.get = function(callback) {
        $.get(this.base_url, function(data) {
            var total_price = 0;
            var adjusted = $.map(data.items, function(obj, idx) {
                var price_total_item = obj.cnt * obj.price;
                total_price += price_total_item;
                return {
                    currency_symbol: data.currency_symbol,
                    article_nr: idx,
                    name: obj.name,
                    cnt: obj.cnt,
                    price: obj.price,
                    price_total_item: price_total_item
                };
            });
            callback(adjusted, total_price, data.currency_symbol);
        }, "json");
    };
});
