Updated the javascript part to support a custom JSON protocol. Also moved all the objects and functions out of the WINDOW namespace.