Fixed bug updating selectedImageIndex JavaScript viewer