var MealItemsBO = new Class({
	Implements: Events,
	initialize: function(aScale){
		this.gdascale = aScale;
		this.items = new Hash();
		this.last_item = null;
		
		//menu items totals
		this.meal = new NutritionVO();
		//gda values (percentage of total against scale)
		this.gda = new NutritionVO();
	},
	
	setGDAScale: function(aScale) {
		this.gdascale = aScale;
		this.items.getKeys().each(function(key,i) {
			var item = this.items.get(key);
			item.meta.gda.calculateGDAWith({item:item.meta.mass, scale:this.gdascale});
		}.bind(this));
		this.calculateGDAValues();
		this.fireEvent("gdaChanged");
	},
	
	add: function(item) {
		this.meal.increaseBy(item.nutrition.bymass);
		
		item.meta.storeKey = item.meta.id+$time()
		item.meta.gda = new NutritionVO();
		item.meta.mass = new NutritionVO(item.nutrition.bymass);
		item.meta.gda.calculateGDAWith({item:item.meta.mass, scale:this.gdascale});
		
		this.items[item.meta.storeKey] = item;
		this.last_item = item;

		this.calculateGDAValues();
		this.fireEvent("addedMenuItem");
	},
	
	remove: function(item) {
		this.meal.decreaseBy(item.nutrition.bymass);
		
		this.items.erase(item.meta.storeKey);
		this.calculateGDAValues();
		
		this.fireEvent("removedMenuItem");
	},
	
	calculateGDAValues: function() {
		this.gda.calculateGDAWith({item:this.meal, scale:this.gdascale});
		this.fireEvent("finishedUpdatingMenu");
	}
	
});