



/*
     FILE ARCHIVED ON 12:14:27 Feb 7, 2011 AND RETRIEVED FROM THE
     INTERNET ARCHIVE ON 12:40:04 Nov 5, 2011.
     JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.

     ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
     SECTION 108(a)(3)).
*/
var FormBuilderLightbox = {
    options: {
        closeable: true
    },

    Hide: function () {
        //Reshow the hidden elements
        $$("body select, object, embed").each(function (obj) {
            obj.style.visibility = "";
        });

        //Do an after hide event if there is one
        if (this.options.beforeHide)
            this.options.beforeHide(this.options);

        //Hide the light box.
        $("FormBuilderLightBox").hide();
        $("lightbox_content").hide();

        //BLS 2010-05-03 Added
        //Show certain elements
        $$("object, embed, select").invoke("show");
    },

    Show: function (options) {
        //Add the user defined options
        Object.extend(this.options, options);

        //Build the lightbox if needed
        if (!$("FormBuilderLightBox"))
            this.constructLightBox();

        //Do an before show event if there is one
        if (this.options.beforeShow)
            this.options.beforeShow(this.options);

        //Set close event
        if (this.options.closeable)
            $("FormBuilderLightBox").onclick = this.Hide.bind(this);
        else
            $("FormBuilderLightBox").onclick = null;

        //Show the box
        $("FormBuilderLightBox").show();

        //Set the dimensions and position of the containers
        this.setPlains();

        //Hide certain elements
        $$("object, embed, select").invoke("hide");

        //Do an after show event if there is one
        if (this.options.afterShow)
            this.options.afterShow(this.options);

        //Show the light box content.
        $("lightbox_content").show();
    },

    constructLightBox: function () {
        //Build the lightbox overlay and the content containers
        var lightBox = new Element("div", { "id": "FormBuilderLightBox", "class": "lightbox", "style": "display: none; position: fixed !important; top: 0; left: 0; zIndex: 9000;" });
        var lightBoxContent = new Element("div", { "id": "lightbox_content", "style": "position: fixed !important; left: 0px; top: 0px; zIndex: 9001;" });
        lightBoxContent.insert(new Element("div", { "class": "lightbox-content" }));

        //Add to the container or body.
        if (this.options.container) {
            this.options.container.insert(lightBox);
            this.options.container.insert(lightBoxContent);
        } else {
            document.body.appendChild(lightBox);
            document.body.appendChild(lightBoxContent);
        }
    },

    setPlains: function () {
        var lightBox = $("FormBuilderLightBox");
        var lightBoxContent = $("lightbox_content");
        var viewPort = document.viewport.getDimensions();
        var scrollOffsets = document.viewport.getScrollOffsets();
        var contentDimensions = lightBoxContent.getDimensions();

        lightBox.style.width = viewPort.width + "px";  // use full page height
        lightBox.style.height =  viewPort.height + "px"; // use full page width
        //lightBox.style.top = scrollOffsets.top + "px";  //
        //lightBox.style.left = scrollOffsets.left + "px";

        lightBoxContent.style.left = ((viewPort.width / 2) - (contentDimensions.width / 2)) + "px";
        lightBoxContent.style.top = ((viewPort.height / 2) - (contentDimensions.height / 2)) + "px";
    }
};
