Building = {
	BuildingNames : new Array(),
	SectionNames : new Array(),
	getAll : function(){
		q = {Method : "Building.getAll"}
		API.query(q,Building.displayAll);
	},
	get : function(id, callback){
		q = {Method : "Building.get", Id : id}

		if(callback!=undefined)
			API.query(q, callback);
		else
			API.query(q);
	},
	getSections : function(id, callback){
		$(".refresh").hide();
		q = {Method : "Building.getSections", Id : id}
		
		if(callback != undefined)
			API.query(q, callback);
		else
			API.query(q,Section.display);
	},
	set : function(id){
		Building.Current = Building.all.Buildings[id]
		Building.getSections(Building.Current.Id);
		$(".building").attr("id", "building" + Building.Current.Id)
		txt = "<h3>"+Building.Current.Name+"</h3><p>"+Building.Current.Description+"</p>";
		$("#buildingINFO").html(txt);
		UI.showStep(2);
	},
	clear : function(){

	},
	displayAll : function(json){
		Building.all = json;
		txt = "";
		for(i=0;i<json.Buildings.length;i++){
			B = json.Buildings[i];
			
			B.Count.Total = parseInt(B.Count.Full[1]) + parseInt(B.Count.Half[1]) + parseInt(B.Count.Accessible[1]);
			B.Count.Free = parseInt(B.Count.Full[0]) + parseInt(B.Count.Half[0]) + parseInt(B.Count.Accessible[0]);
			
			if(B.Count.Free <= 0)
				c = " inactive";
			else
				c = "";
				

			txt += "<li><a class=\"wide_btn"+c+"\" value=\""+i+"\">"+B.Name+" ("+B.Count.Free+")"+"</a></li>";
		}
		$("#AllBuildings").html(txt);
		Building.bind();
	},
	bind : function(){
		$("#AllBuildings li a").each(function(){
			if($(this).hasClass("inactive")) {
				
			} else {
				$(this).click(function(){
					id = $(this).attr("value");
					Building.set(id)
				});
			}
		})
	}
}
