Tzzbox.js: move scaling code to a function and some cleanup