﻿function GenericToolTip()
{
}
GenericToolTip.prototype.Show = function( evt, content, className )
{
    if( !this.IsShowing && this.Container )
    {
        this.IsShowing = true;
        this.Container.className = className;
        this.Container.innerHTML = content;
        this.Container.style.display = "";
    }
    this.Refresh( evt );
};
GenericToolTip.prototype.Hide = function( evt )
{
    if( this.IsShowing && this.Container )
    {
        this.IsShowing = false;
        this.Container.style.display = "none";
        this.Container.innerHTML = "";
    }
};
GenericToolTip.prototype.Refresh = function( evt )
{
    if( this.IsShowing && this.Container )
    {
        if( evt ) evt = new xEvent( evt );
        var x = 0;
        var y = 0;
        var w = xWidth( this.Container );
        var h = xHeight( this.Container );
        var cw = xClientWidth();
        var ch = xClientHeight();
        if( ( evt.pageX + w + 15 ) > cw ) x = evt.pageX - w - 10;
        if( x <= 0 ) x = evt.pageX + 15;
        if( ( evt.pageY + h + 10 ) > ch ) y = evt.pageY - h - 10;
        if( y <= 0 ) y = evt.pageY + 10;    
        xLeft( this.Container, x );
        xTop( this.Container, y );
    }
};
GenericToolTip.prototype.Init = function()
{
    this.Container = CreateElement( "div", document.body );
    this.Container.className = this.ClassName;
    this.Container.style.position = "absolute";
    this.Container.style.display = "none";
    this.IsShowing = false;
};

var ToolTip = new GenericToolTip();
xAddEventListener( window, "load", function() { ToolTip.Init(); } );  