Async javascript + some refactoring

This adds almost all the support for async js. All that's left is handling page navigation during execution, since the strategy we're using here (XmlHTTPRequests) doesn't work well when stuck in unload like the callback is.

**This shouldn't be merged until jlipps has a chance to do some code review, since a LOT has been moved around.**