﻿/**
 * Display an image in a new window.
 * @param imgURL URL of the image.
 * @param winTitle Title of the window.
 */
function showImage(imgURL, winTitle) {
    window.status = "Loading image...";
    var img = new Image();
    img.src = imgURL;
    img.onload = function() {
        winOpen(imgURL, winTitle, 0, 0, img.width, img.height);
    };
    window.status = "";
}

/**
 * Image previewer suited for large images (allows for scrooling).
 * @param imgURL URL of the image.
 * @param winTitle Title of the window.
 */
function showLargeImage(imgURL, winTitle) {
    window.status = "Loading image...";
    var img = new Image();
    img.src = imgURL;
    img.onload = function() {
        if ((img.width >= screen.width) || (img.height >= screen.height)) {
            winOpen(imgURL, winTitle, 1, 1, img.width, img.height);
        } else {
            winOpen(imgURL, winTitle, 0, 0, img.width, img.height);
        }
    };
    window.status = "";
}

function winOpen(imgURL, winTitle, scrollbars, resize, w, h) {
    var parameters = "toolbar=0, directories=0, status=0, scrollbars=" + scrollbars + ", resize=" + resize + ", menubar=0, height=" + h + ", width=" + w;
    var imageWindow = window.open("", "_blank", parameters);
    imageWindow.location.href = imgURL;
    code = '<html><head><title>' + winTitle + '</title></head><body onclick="javascript:var click = false; if (event.which != null) { this.click = (event.which == 1); } else if (event.button != null) { this.click = (event.button == 0); } if (this.click) { window.close(); };"><img style="position:absolute; left:0px; top:0px;" alt="' + winTitle + '" src="' + imgURL + '" /></body></html>';
    imageWindow.document.write(code);
}