/* Category Model- Responsible for loading and managing categories */
function CategoryModel(settings, webservice)
{
	this.WebService= webservice;
	this.Categories= [];
	this.CategoryMap= [];
	this.CategoryView= null;
	this.OnCategoriesLoaded= null;
	this.SetView= function(x) { 
		this.CategoryView= x; 
	};	
	this.ParseCategoryList= function(statusCode, jsonObject, cm) {
		cm.Categories= jsonObject.items;
		cm.CategoryMap= [];
		for(var ii= 0; ii<jsonObject.items.length; ii++)
		{
			var item= jsonObject.items[ii];
			cm.CategoryMap[item.ID]= item;
		}
		
		if(cm.CategoryView) { 
			cm.CategoryView.Refresh(cm);
		}
		
		if(cm.OnCategoriesLoaded) {
			cm.OnCategoriesLoaded(cm);
		}
		cm.OnCategoriesLoaded= null; // don't do this unless asked.
	};
	this.Load= function(onCategoriesLoaded) {
		this.OnCategoriesLoaded= onCategoriesLoaded;
		this.WebService.GetCategoryList(this.ParseCategoryList, this);
	};
}

