+ }
+ elem.style.opacity = amount;
+}
+
+function position_image(img, backend_width, backend_height, offset, box)
+{
+ var screen_size = find_width();
+ var dpr = find_dpr();
+ var width, height;
+
+ if (backend_width == -1) {
+ // no size information, use our pessimal guess
+ var adjusted_size = max_image_size(screen_size);
+ width = adjusted_size[0];
+ height = adjusted_size[1];
+ } else {
+ // use the exact information
+ var adjusted_size = pick_image_size(screen_size, [ backend_width, backend_height ]);
+ width = adjusted_size[2];
+ height = adjusted_size[3];
+ }
+
+ var extra_x_offset = find_width()[0] * offset;
+ var left = (screen_size[0] - width) / 2;
+ var top = (screen_size[1] - height) / 2;
+
+ if (global_infobox) {
+ top = Math.max(top - dpr * (24/2), 0);
+ }
+
+ // center the image on-screen
+ img.style.position = "absolute";
+ img.style.left = (left / dpr) + "px";
+ img.style.transform = "translate(" + extra_x_offset + "px,0px)";
+
+ if (box) {
+ img.style.top = Math.min(top + height, screen_size[1] - 24) / dpr + "px";
+ img.style.height = "24px";
+ img.style.width = null;
+ img.style.whiteSpace = 'nowrap';
+ if (offset == 0) {
+ // Hide the box if there's no room for all the text.
+ img.style.opacity = (img.clientWidth < width / dpr + 10) ? null : 0.0;
+ }
+ img.style.width = (width / dpr) + "px";
+ } else {
+ img.style.top = (top / dpr) + "px";
+ img.style.lineHeight = (height / dpr) + "px";
+ img.style.width = (width / dpr) + "px";
+ img.style.height = (height / dpr) + "px";
+ }
+}
+
+function update_shown_images()
+{
+ // Go through and remove all the elements that are not supposed to be there.
+ var main = document.getElementById("main");
+ var children = main.children;
+ var to_remove = [];
+ for (var i = 0; i < children.length; i++) {
+ var child = children[i];
+ var inum = null;
+ if (child.className === "fsimg") {
+ inum = parseInt(child.id);
+ } else if (child.className === "fsbox") {
+ inum = parseInt(child.id.replace("_box", ""));