New version of the Javascript

Rewrite javascript to be asynchronous and hopefully faster. Also tidies up the
output, especially for includes.
Separate module types from modules, and clear up various bits of code
Merge pull request #47 from lpw25/master

New version of the javascript and a lot of tidying up