+function parse_image_num(default_value) {
+ var num = parseInt(window.location.hash.substr(1));
+ if (num >= 1 && num <= global_image_list.length) { // and then num != NaN
+ return (num - 1);
+ } else {
+ return default_value;
+ }
+}
+window['parse_image_num'] = parse_image_num;
+
+function check_for_hash_change() {
+ var num = parse_image_num(-1);
+ if (num != -1 && num != global_image_num) {
+ global_image_num = num;
+ relayout();
+ }
+}
+
+function toggle_immersive() {
+ if (global_default_opacity == 0.7) {
+ global_disabled_opacity = 0.0;
+ global_default_opacity = 0.0;
+ global_highlight_opacity = 0.2;
+ global_infobox = false;
+ document.getElementById('immersivetoggle').innerHTML = 'Show decorations';
+ } else {
+ global_disabled_opacity = 0.1;
+ global_default_opacity = 0.7;
+ global_highlight_opacity = 1.0;
+ global_infobox = true;
+ document.getElementById('immersivetoggle').innerHTML = 'Hide all decorations';
+ }
+ relayout();
+}
+window['toggle_immersive'] = toggle_immersive;
+
+var swiping = false;
+var swipe_start_x = 0;
+
+function set_swipe_pos(x, transition)
+{
+ x = Math.max(x, -window.innerWidth);
+ x = Math.min(x, window.innerWidth);
+ if (!can_go_previous()) {
+ x = Math.min(x, window.innerWidth / 8);
+ }
+ if (!can_go_next()) {
+ x = Math.max(x, -window.innerWidth / 8);
+ }
+
+ var dpr = find_dpr();
+ var main = document.getElementById("main");
+ var children = main.children;
+ var to_remove = [];
+ for (var i = 0; i < children.length; i++) {
+ var child = children[i];
+ if (child.className === "fsimg") {
+ var inum = parseInt(child.id);
+ var offset = inum - global_image_num;
+ child.style.transition = transition;
+ child.style.transform = "translate(" + (x + find_width()[0] * offset / dpr) + "px,0px)";
+ } else if (child.className === "fsbox") {
+ var inum = parseInt(child.id.replace("_box", ""));
+ var offset = inum - global_image_num;
+ child.style.transition = transition;
+ child.style.transform = "translate(" + (x + find_width()[0] * offset / dpr) + "px,0px)";
+ }
+ }
+}
+
+function start_swipe(e)
+{
+ swiping = true;
+ swipe_start_x = e.changedTouches[0].pageX;
+}
+
+function end_swipe(e)