﻿function imageHighlight_createHeader() 
{
    var oHeader = document.createElement("div");
    oHeader.setAttribute("id", "imageHighlight_Header");
    oHeader.setAttribute("align", "center");
    document.getElementById("imageHighlight").appendChild(oHeader);
    document.getElementById("imageHighlight_Header").innerHTML = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"width:100%; height:30px;\"><tr><td style=\"vertical-align:middle; color:#ffffff; padding-right:10px; text-align:right;\"><div class=\"Layout-Generics-FakeLink\" onclick=\"Javascript: imageHighlight_CloseWindow();\">(Close)</div></td></tr></table>";
}

function imageHighlight_CloseWindow() {
    if (document.getElementById("imageHighlight")) {
        document.getElementById("imageHighlight").removeChild(document.getElementById("imageHighlight_Header"));
        document.getElementById("imageHighlight").removeChild(document.getElementById("imageHighlight_Image"));
        document.getElementsByTagName("body").item(0).removeChild(document.getElementById("imageHighlight"));
        document.getElementsByTagName("body").item(0).removeChild(document.getElementById("imageHighlight_FullScreenWashout"));

    }
}

function imageHighlight_createPopUp() 
{
    if (!document.getElementById("imageHighlight")) {
        var iWidth = 400;
        var iHeight = 500;
        var oDialog = document.createElement("div");
        var oWashout = document.createElement("div");
        oDialog.setAttribute("id", "imageHighlight");
        oDialog.setAttribute("name", "imageHighlight");
        oWashout.setAttribute("id", "imageHighlight_FullScreenWashout");
        oDialog.setAttribute("align", "center");
        document.getElementsByTagName("body").item(0).appendChild(oDialog);
        document.getElementsByTagName("body").item(0).appendChild(oWashout);
        document.getElementById("imageHighlight").style.width = iWidth + "px";
        document.getElementById("imageHighlight").style.height = iHeight + "px";
        document.getElementById("imageHighlight").style.marginLeft = (0 - (iWidth / 2)) + "px";
        document.getElementById("imageHighlight").style.marginTop = (0 - (iHeight / 2)) + "px";
        document.getElementById("imageHighlight").style.overflow = 'auto';

        document.getElementById("imageHighlight_FullScreenWashout").style.height = document.body.scrollHeight + "px";
    }
}

function imageHighlight_LoadImage() {
    if (document.getElementById("imageHighlight_Image")) {
        var pic = document.getElementById("imageHighlight_Image");
        var h = pic.height;
        var w = pic.width;

        if (!pic.height || !pic.width || (w - 32) < 0 || (h-2)<0) {
            setTimeout("imageHighlight_LoadImage()", 50);
        }
        else {


            var ScrollTop = document.body.scrollTop;

            if (ScrollTop == 0) {
                if (window.pageYOffset)
                    ScrollTop = window.pageYOffset;
                else
                    ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
            }

            document.getElementById("imageHighlight").style.width = (w - 32) + "px";
            document.getElementById("imageHighlight").style.height = (h - 2) + "px";
            document.getElementById("imageHighlight").style.marginLeft = (0 - ((w - 32) / 2)) + "px";
            document.getElementById("imageHighlight").style.marginTop = (parseInt(ScrollTop) - ((h - 2) / 2)) + "px";



            imageHighlight_createHeader();
        }
    }
    else {
        setTimeout("imageHighlight_LoadImage()", 50);
    }
}


function imageHighlight_loadImage(url) {
    if (!document.getElementById("imageHighlight_Image")) {
        var oImage = document.createElement("img");
        oImage.setAttribute("id", "imageHighlight_Image");
        oImage.setAttribute("src", "http://images.tafft.co.uk" + url);
        oImage.setAttribute("alt", url);
        oImage.setAttribute("align", "center");
        document.getElementById("imageHighlight").appendChild(oImage);

        imageHighlight_LoadImage();
    }



}

function imageHighlight_showHighlightImage(url) {
    imageHighlight_createPopUp();
    imageHighlight_loadImage(url)
    
    
}




