JS: Check if an image is loaded