javascript waits for images to load