Modularize js & add jamine tests

I refactored the javascript to be more modular (only one global variable, more standard object definition, less implicit dependencies, only three public methods).

Added jasmine tests to test the public, non-api dependent methods