WIP: Major refactor of javascript

This is a massive refactor of the client code, splitting most of it out into modules so that everything is not running rampant in the global namespace.

I'm still iterating on it.

http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html