Room = {
	
	cache:	new Object(),
	
	load:	function(id, display) {
				if (display == null) {
					display = true;
				}
				if(Room.cache.id !== undefined) {
					Room.unload(Room.cache.id);    
				}
				
				if(!Room.loaded(id)) {
				    	Interface.show_throbber(Interface.throbber_coords[id][0], Interface.throbber_coords[id][1]);
					var request = new Ajax.Request('ssi/room.php?id='+id, {
						method: 'get',
						//evalJSON: true,
						onSuccess: function(xmlHTTP) {
							r = xmlHTTP.responseText.evalJSON();
							Room.cache = r;														
							Calendar.load(id, null, null);
							Twitter.getlatest(Room.cache.hashtag);
						},
						onFailure: function(xmlHTTP) {
							error = xmlHTTP.responseText.evalJSON();
						}
					});
				}
			},
		
	unload:	function(id) {
				if(Room.loaded(id)) {				    	
				    	Room.cache = new Object();
					Calendar.unload(id);
					var bubble = $$(id+' .tweet')[0];
					bubble.setAttribute('style', 'display:none');
					return Room.cache;
				}
			},
			
	loaded:	function(id) {
				if(Room.cache.id == id) {
				    return true;
				} else {
				    return false;
				}
			},
			
	clear:	function() {
				Maintenance.clear();
				Interface.clear_selection();
				$('room_table').update(Room.table());
				Maintenance.load(null, $F('select_floor'));
			},	
	
	table:	function() {
				var table = "<table><tr><th>Room</th><th>Type</th><th>Flat</th><th>Floor</th><th>Notes</th><th></th></tr>";
				var floor;
				Room.cache.each(function(r){
					var mrf_button = new button('mrf_button', 'New MRF', null, "Maintenance.show_form('"+r.get('id')+"')"); 
					table += "<tr>";
					table += "<td>"+r.get('number')+"</td>";
					table += "<td>"+r.get('type')+"</td>";
					table += "<td>"+r.get('flat')+"</td>";
					table += "<td>"+Floor.name(r.get('floor'))+"</td>";
					table += "<td>"+r.get('notes')+"</td>";
					table += "<td>"+mrf_button.display()+"</td>";
					table += "</tr>";
				});
				table += "</table>";
				return table;
			}
			
};

