var PortDetailCaption = {
    captionShowing: false,

    ShowCaption: function () {
        var tooltip = document.getElementById("portCaption");
        if (tooltip) {
            tooltip.style.visibility = "visible";
            this.captionShowing = true;
        }
        this.UpdateCaptionLink();
    },

    HideCaption: function () {
        var tooltip = document.getElementById("portCaption");
        if (tooltip) {
            tooltip.style.visibility = "hidden";
            this.captionShowing = false;
        }
        this.UpdateCaptionLink();
    },

    UpdateCaptionLink: function () {
        var tooltip = document.getElementById("portCaption");

        var link = null;
        if (parent) {
            // This can fail if the standalone port viewer is embedded in a frame 
            try {
                link = parent.document.getElementById("portViewerToggleCaption");
            }
            catch (e) {
                link = null;
            }
        }
        if (link == null) {
            link = document.getElementById("portViewerToggleCaption");
        }

        if (link) {
            if (tooltip) {
                link.style.visibility = "visible";
                if (tooltip.style.visibility != "visible") {
                    this.captionShowing = false;
                }
                if (this.captionShowing) {
                    link.innerHTML = "hide caption";
                } else {
                    link.innerHTML = "show caption";
                }
            } else {
                link.style.visibility = "hidden";
            }
        }
    },

    HideCaptionLink: function () {
        var link = null;
        if (parent) {
            // This can fail if the standalone port viewer is embedded in a frame 
            try {
                link = parent.document.getElementById("portViewerToggleCaption");
            }
            catch (e) {
                link = null;
            }
        }
        if (link == null) {
            link = document.getElementById("portViewerToggleCaption");
        }
        if (link) {
            link.style.visibility = "hidden";
        }
    },

    ToggleCaption: function () {
        if (this.captionShowing) {
            this.HideCaption();
        } else {
            this.ShowCaption();
        }
    }
};
