Tidy javascript for UI refactoring

Each changeset has its own minor cleaning/refactoring.  

The overall goal is to start to simplify the js code and refactor rooms etc into something that can be extended and used in more general ways.