Moves javascript into seperate file.

Runs code in window.load event handler. This way the picture is already loaded and its width and height can be determined savely.