Completely new structure of the javascript file

Javascript made maintainable. Hopefully ;-)