function Order()
{
  this._orderTotal = 0;
  this._numItems = 0;
  this._items = [];
  this._itemActive = false;
  this.currentItem = null;
  
  this.update = function()
  {
    for (var i = 0; _items.length; i++){
      this._orderTotal += this._items[0]._itemTotal;
      this._numItems += this._items[0]._numItems;
    }
  }
  
  this.add = function(i)
  {
    this._items.push(i);
    this._orderTotal += i.price * i._multiplier;
    
    var title = i.title;
    var quantity = i._multiplier;
    var price = formatCurrency(i.price * quantity);
    
    $("ul#summary_items li.nil").remove();
    $("ul#summary_items").createAppend(
      'li',{},
      '<span class="title">'+quantity+' '+title+'</span>' +
        '<span class="price">'+price+'</span>'
        +'<ul><li>With Rice Pilaf and Baked Beans</li>'
        +'<li>' + i._special + '</li></ul>'
    );
    
    this.updateTotals();
    
    console.log(serialize(i));
  }
  
  this.updateTotals = function()
  {
    var sub = $("#order_subtotal");
    var tip = $("#order_tip");
    var tot = $("#order_total");
    
    sub.text(formatCurrency(this._orderTotal));
    
    var t = 10;
    tot.text(formatCurrency(this._orderTotal + t));
    
  }

  this.activateItemWindow = function() {
    this._itemActive = true;
  }
}

function Item(id, title, price)
{
  this.id = id;
  this.title = title;
  this.price = price;
  
  this._label;
  this._special;
  this._sides = [];
  this._options = [];
  this._itemTotal = price;
  this._multiplier = 1;
  this._numItems = 0;
  
  this._priceField = null;
  
  this.updateOption = function (e,p)
  {
    console.log("updating option \nsdfsdf\nsdfSDF:" + e.value);
    if (e.checked == true){
      this._itemTotal += p;
      this._options.push(e);
    }
    else {
      this._itemTotal -= p;
      var idx = jQuery.inArray(e, this._options);
      if (idx != -1)
        this._options.splice(idx,1);
    }
    var field = $("#item_ordertotal");
    field.attr("value", formatCurrency(this._price()));
  }
  
  this.updateSides = function(e)
  {
    if (e.checked == true)
      this._sides.push(e)
    else {
      var idx = jQuery.inArray(e, this._sides);
      if (idx != -1)
        this._sides.splice(idx,1);
    }
    
    console.log("sides length: " + this._sides.length)
  }
  
  this.updateMultiplier = function(n)
  {
    this._multiplier = n;
    
    var field = $("#item_ordertotal");
    field.attr("value",formatCurrency(this._price()));
  }
  
  this.updateLabel = function(n)
  {
    this._label = n.value;
  }
  
  this.updateSpecial = function(n)
  {
    this._special = n.value;
  }
  
  this.add = function()
  {
    Order.add(this);
  }
  
  this._price = function()
  {
    return Math.round(this._itemTotal * this._multiplier * 100) / 100;
  }
}