﻿//Create the InfoPanel object
var infoPanel;

function InfoPanel() {
    //Create InfoPanel object
    $("#infoPanel").jqm({
        overlayClass: "infopaneloverlay"     
    });
}

InfoPanel.prototype.showMessage = function (contenturl, title, width, height, modal, islocal) {
    //Create show message method

    if (IsIE6()) {
        //The user is using IE6, open the page in a new window instead
        window.open(contenturl);
        return;
    }

    //Initialize the width and height if they weren't specified
    if (!width) { width = 250; }
    if (!height) { height = 150; }

    //Limit the number of characters in the title
    if (title.length > 70) {
        title = title.substring(0, 70);
    }

    //Set the InfoPanel's HTML
    var TitleBar = "<div id='infopaneltitle'>" + title + "</div><div id='infopanelclose'></div>";
    var Content;
    if (islocal == true) {
        //Copy the local content
        Content = "<div id='infopanelcontent' style='width:" + (width - 20) + "px;height:" + (height - 50) + "px;'>" + $("#" + contenturl).html() + "</div>";
    }
    else {
        //Use an iframe to display the content
        Content = "<div id='infopanelcontent'><iframe id='infopanelpage' src='" + contenturl + "' height='" + (height - 50) + "' width='" + (width - 20) + "' frameborder='0' /></div>";
    }
    $("#infoPanel").html(TitleBar + Content);

    //Set the InfoPanel settings
    $("#infoPanel").width(width + "px").height(height + "px").css("margin-left", ((width / 2) * -1) + "px").css("margin-top", ((height / 2) * -1) + "px");

    //Hide the modal window if it is visible
    $("#infoPanel").jqmHide();

    //Show the overlay if set to modal
    if (modal == true) {
        $("#infoPanel").jqm({ overlay: 80, modal: true });
    }
    else {
        $("#infoPanel").jqm({ overlay: 0, modal: false });
    }

    //Show the InfoPanel
    $("#infoPanel").jqmAddClose("#infopanelclose").draggable().jqmShow();
}

$(document).ready(function() {
    //Perform these operations when the page loads

    //Create the InfoPanel div
    var infoPanelDiv = document.createElement("DIV");
    infoPanelDiv.setAttribute("id", "infoPanel");
    document.body.appendChild(infoPanelDiv);

    //Initialize the InfoPanel
    infoPanel = new InfoPanel();
});
