Made main.js "library-only"

The file can now be included multiple times; it contains only function
definitions.

This way, we don't have to call these functions with the "window.top." prefix
anymore.