js refactor

This branch refactors the javascript into its own file and restructures the game loop.