slideshow.js: fitting the image correctly, refactoring, fixing preload issues, ...

I just reapplied my changes to the current master. This is a hack to avoid the effort of rebasing #1106.

It is is fixing #1073, #1074 and some other issues.