/// <reference path="jquery.js" />

var GB_DONE = false;
var GB_HEIGHT = 400;
var GB_WIDTH = 400;
var activeWindowId = null;

function GB_show(windowId, height, width) {
    activeWindowId = windowId;
    GB_HEIGHT = height || 400;
    GB_WIDTH = width || 400;
    if (!GB_DONE) {
        $(document.body)
      .append("<div id='GB_overlay'></div>");
        $("#" + activeWindowId + " img").click(GB_hide);
        $("#GB_overlay").click(GB_hide);
        $(window).resize(GB_position);
        GB_DONE = true;
    }

    $("#" + activeWindowId).show();
    $("#GB_overlay").show();
    GB_position();

}

function GB_hide() {
    $("#" + activeWindowId).hide();
    $("#GB_overlay").hide();
}

function GB_position() {
    var de = document.documentElement;
    var w = self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    var h = self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
    var offset = document.documentElement.scrollTop || document.body.scrollTop;
    var posLeft = (w - GB_WIDTH) / 2;
    var posTop = (h - GB_HEIGHT) / 2;
    $("#" + activeWindowId).css({ width: GB_WIDTH + "px", height: GB_HEIGHT + "px",
        left: posLeft + "px", top: posTop + "px"
    });
    $("#GB_overlay").css({ top: offset + "px" });
}
