﻿/* ==================================================
** This script handles the popup of program notes.
** ================================================== */

// 0 means disabled; 1 means enabled;
var pnItem = null;
function showProgramNotes() {
    // Only load the popup if it is not already open.
    if (pnItem != null) {
        $("#pnBackground").css({
            "opacity": "0.7"
        });
        $("#pnBackground").fadeIn("slow");
        $(pnItem).fadeIn("slow");
    }
}
function hideProgramNotes() {
    // Only hide the popup if it's visible.
    if (pnItem != null) {
        $("#pnBackground").fadeOut("slow");
        $(pnItem).fadeOut("slow");
    }
    pnItem = null;
}

function centerProgramNotes() {
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    //var popupHeight = $("#" + notesId).height();
    //var popupWidth = $("#" + notesId).width();
    var popupHeight = windowHeight - 20;
    var popupWidth = windowWidth - 20;

    // Center based ont eh current client values.
    /*
    $("#" + notesId).css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    */
    /*
    $(pnItem).css({
        "position": "absolute",
        "top": 10,
        "left": 10
    });
    */
    
    // Only need force for IE6
    $("#pnBackground").css({
        "height": windowHeight
    });
}

$(document).ready(function() {
    // Bind to the click event of each popup link in order to show the popup.
    $("a.pnLink").each(function(i) {
        $(this).click(function(e) {
            pnItem = $(this).parent().find("div.pnPopup");
            centerProgramNotes()
            showProgramNotes();
        });
    });
    $("a.pnlLink").each(function(i) {
        $(this).click(function(e) {
            pnItem = $(this).parent().find("div.pnlPopup");
            centerProgramNotes()
            showProgramNotes();
        });
    });

    // Bind to the click event of each close button in order to close the popup.
    $(".pnClose").click(function() {
        hideProgramNotes();
    });

    // Bind to the click event of the backgroun in order to close the popup.
    $("#pnBackground").click(function() {
        if (pnItem != null) {
            hideProgramNotes();
        }
    });

    // Bind to the escape key event in order to close the popup.
    $(document).keypress(function(e) {
        if (e.keyCode == 27) {
            if (pnItem != null) {
                hideProgramNotes();
            }
        }
    });
});

