﻿function matchColumnHeights() {
    var divisions = new Array();
    divisions[0] = document.getElementById("divContextPane");
    divisions[1] = document.getElementById("divMainContent");

    var max_height = 0;
    for (var i = 0; i < divisions.length; i++) {
        var div_height = 0;
        var div = divisions[i];

        if (div.offsetHeight) {
            div_height = div.offsetHeight;
        }
        else if (div.style.pixelHeight) {
            div_height = div.style.pixelHeight;
        }

        max_height = Math.max(max_height, div_height);
    }

    // When the maximum height of both the divisions are determined, simply set
    // the height of 'divCentralTile' division to the maximum height. This way
    // the tiled background will grow to the maximum height, covering both the 
    // divisions above.
    document.getElementById("divCentralTile").style.height = max_height + "px";
}

function getThumbnailDiv() {
    return document.getElementById(window.thumbnail_div_name);
}

function getContentDiv() {
    return document.getElementById(window.content_div_name);
}

function getPictureCaption() {
    return document.getElementById(window.pic_caption_name);
}

function getPictureSource() {
    return document.getElementById(window.pic_source_name);
}

function getPictureContent() {
    return document.getElementById(window.pic_content_name);
}

function thumbnailClicked(index) {
    var pictureCaption = getPictureCaption();
    pictureCaption.innerHTML = window.alternate[index];

    var pictureContent = getPictureContent();
    pictureContent.innerHTML = window.contents[index];
    
    var pictureSource = getPictureSource();
    pictureSource.setAttribute("src", window.images[index]);
    pictureSource.setAttribute("alt", window.alternate[index]);
    pictureSource.setAttribute("visible", "true"); // Show the image.
}

function imageTagFromString(thumbnails, alternate, index) {
    var image_tag = "<img src=\"" + thumbnails[index] + "\" ";
    image_tag += "alt=\"" + alternate[index] + "\" ";
    image_tag += "onClick=\"thumbnailClicked(" + index + ");\" />";
    return image_tag;
}

function initializePictureBox(thumbnails, alternate) {
    var thumb_output = "";
    for (x in thumbnails) {
        thumb_output += imageTagFromString(thumbnails, alternate, x);
    }

    var divThumbnail = getThumbnailDiv();
    divThumbnail.innerHTML = thumb_output;
    thumbnailClicked(0); // Show the first image.
}

function selectTextBoxContent(obj) {
    var text_val = eval(obj);
    text_val.focus();
    text_val.select();
    
    if (!document.all)
        return; // IE only

    r = text_val.createTextRange();
    r.execCommand('copy');
}
