﻿// Register a new Namespace
Type.registerNamespace("MyServices");

// Define the constructor of the Location class
MyServices.Location = function (uiElement)
{
    // Call base class just for completeness
    MyServices.Location.initializeBase(this);
    
    this._uiElement = uiElement;
    this._xAxis = 0;
    this._yAxis = 0;
}

// Define the properties and methods of the Location class
// using the Prototype Design Pattern
MyServices.Location.prototype= 
{
    
    // Define UIElement Property
    get_uiElement:function() 
    {
        // Get
        return this._uiElement;
    },
    set_uiElement:function(value) 
    {
        // Set
        this._uiElement = value;
    },
    
    // Define ShowPopupInfo method that is setting the content and the location of the popup window.
    ShowPopupinfo:function(event, Content) 
    {
        // Set the location of the popup window
        this._xAxis = event.clientX;
        this._yAxis = event.clientY;

        var uiElement = $get(this.get_uiElement());

        // Show the UI element
        if (uiElement != null) 
        {
            uiElement.innerHTML = Content
            uiElement.style.visibility = "visible";
            uiElement.style.display = "inline";
            uiElement.style.left = 5 + this._xAxis + "px";
            uiElement.style.top = 5 + this._yAxis + "px";
        }        
    },
    
    // Define HidePopupInfo method that is used to hide
    // the UI popup window
    HidePopupInfo:function() 
    {
        var uiElement = $get(this.get_uiElement());
        if (uiElement != null) {
            uiElement.style.visibility = "hidden";
            uiElement.style.display = "none";
        }
    }
}

// Register the class
MyServices.Location.registerClass("MyServices.Location");

var myLocation = null;
function pageLoad(sender, args) 
{
    // Create a new instance of the class
    myLocation = new MyServices.Location("hotSpotOverContent");
    
    // Hide the popup div
    myLocation.HidePopupInfo();
}

// Method called by the page controls
// to update the UI with the information
// from the ajax service
function GetHotSpotContent(event, Content) 
{
    myLocation.ShowPopupinfo(event, Content);
}

function HidePopup() 
{
    // Hide the popup div
    myLocation.HidePopupInfo();
}
