﻿function NHLPAPopup(name)
{
    this.iShadowOffset = 11;
    this.iOverallOffset = 18;    
    this.sName = name;
    this.sHtml;
    this.sAnchorPosition; // TOP CENTER or LEFT BOTTOM or RIGHT TOP
    this.eTarget;
    this.x;
    this.y;
    this.bVisible = false;
}

NHLPAPopup.prototype.updatePosition = function()
{
    // position the pointer first...
    var popupPointerTop = this.y;
    var popupPointerLeft = this.x;

    $("#" + this.sName + "_Pointer").css("top", popupPointerTop);
    $("#" + this.sName + "_Pointer").css("left", popupPointerLeft);

    // position the content to the pointer
    
    try
    {    
        $("#" + this.sName).css("top", this.y - ($("#" + this.sName).height() / 2) + ($("#" + this.sName + "_Pointer").height() / 2));
        $("#" + this.sName).css("left", this.x + this.iOverallOffset);
    }
    catch(oError)
    { }
    
    if (this.bVisible)
    {
        $("#" + this.sName).css("visibility", "visible");
    }
    else
    {
        $("#" + this.sName).css("visibility", "hidden");
    }
}

NHLPAPopup.prototype.show = function(x, y)
{
    this.bVisible = true;
    this.x = x;
    this.y = y;
    this.updatePosition();
    $("#" + this.sName + "_Pointer").css("visibility", "visible");
}

NHLPAPopup.prototype.hide = function()
{
    this.bVisible = false;
    $("#" + this.sName).css("visibility", "hidden");
    $("#" + this.sName).css("top", "0px");
    $("#" + this.sName).css("left", "0px");
    $("#" + this.sName + "_Pointer").css("top", "0px");
    $("#" + this.sName + "_Pointer").css("left", "0px");    
    $("#" + this.sName + "_Pointer").css("visibility", "hidden");    
}

NHLPAPopup.prototype.create = function()
{
    // error checking used in development only
    if ($(this.sName).length > 0)
    {
        alert("The popup id already exists: " + this.sName);
        return false;
    }
    if ($(this.eTarget) == "")
    {
        alert("You must specify a target element.");
        return false;
    }


    // ok all passed... lets do some work
    // create the html elements needed

    $("body").append("<div id=\"" + this.sName + "\" class=\"NHLPAPopup\"></div>");
    $("body").append("<div id=\"" + this.sName + "_Pointer\" class=\"NHLPAPopupPointer\"><img src=\"/JS/NHLPA/Images/Popup/LeftPointer.png\" /></div>");

    $("#" + this.sName).css("top", "0px");
    $("#" + this.sName).css("left", "0px");
    $("#" + this.sName + "_Pointer").css("top", "0px");
    $("#" + this.sName + "_Pointer").css("left", "0px");

    // load the popup text
    $("#" + this.sName).html
    (
        $.ajax
        (
            {
                url: "/JS/NHLPA/PopupHtml.html",
                async: false
            }
        ).responseText
    );
    // set up events

    $("#" + this.sName).click(function(event)
    {
        event.stopPropagation();
    });
}

NHLPAPopup.prototype.setHtml = function(html)
{
    this.sHtml = html;
    $("#" + this.sName + " .NHLPAPopupContentContainer").empty().append(html);
    this.updatePosition();
}