﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="base.js"          />

var TheCurrentTT = null

function MyToolTip()
{
    this.ToolTip   = null
    this.Container = null
    this.Offset    = 0
}

MyToolTip.prototype.Initialize = function(cont,tooltiptxt,offset)
{
    if (offset) this.Offset = offset
    
    this.Container = cont
    this.Container.Parent = this
    this.ToolTip = document.createElement('table')
    
    this.ToolTip.cellpadding = '0'
    this.ToolTip.cellspacing = '0'
    this.ToolTip.border      = '0'
    
    this.ToolTip.style.borderCollapse = 'collapse'
    this.ToolTip.style.zIndex = '1000'
    
    var r1 = this.ToolTip.insertRow(-1)
    var r2 = this.ToolTip.insertRow(-1)
    
    var c1 = r1.insertCell(-1)
    var c2 = r1.insertCell(-1)

    //r1.style.backgroundColor = '#FFFFFF'
    
    //c1.innerHTML = '<img align="right" style="padding-right: 10px;" src="images/tip.gif" />' 
    
    c1.style.padding  = '10px 4px 5px 10px'
    c1.style.fontSize = '10px'
    c1.style.color    = '#002d47' 
    c1.style.background = 'url("/images/tooltip_bg.png") left no-repeat'
    //SetClass(c2, 'tooltip') 
    c1.innerHTML = '<div style="padding: 0px 0px 3px 0; white-space:nowrap">' + tooltiptxt + '</div>'

	c2.style.padding  = '10px 2px 5px 2px'
    c2.style.background = 'url("/images/tooltip_right.png") right no-repeat'
    
    this.ToolTip.style.visibility = 'hidden'
    this.ToolTip.style.display    = 'none'
    this.ToolTip.style.position   = 'absolute'

    document.body.appendChild(this.ToolTip)
    
    $addHandler(this.Container, 'mouseover', function()
    {
        var TheToolTipBounds   = Sys.UI.DomElement.getBounds(this.Parent.ToolTip)
        var TheContainerBounds = Sys.UI.DomElement.getBounds(this.Parent.Container)

        if (Sys.Browser.agent == Sys.Browser.InternetExplorer)
        {
            if (Sys.Browser.version >= 7)
            {
                TheContainerBounds.x = TheContainerBounds.x + 2
                TheContainerBounds.y = TheContainerBounds.y + 2
            }
        }
        
        this.Parent.ToolTip.style.visibility = 'visible'
        this.Parent.ToolTip.style.display    = 'block'

		// this.Parent.ToolTip.style.left       = (TheContainerBounds.x + TheContainerBounds.width - this.Parent.ToolTip.offsetWidth + this.Parent.Offset) + 'px'
		// this.Parent.ToolTip.style.top        = (TheContainerBounds.y - this.Parent.ToolTip.offsetHeight - 4) + 'px'
        this.Parent.ToolTip.style.left       = (TheContainerBounds.x - 4) + 'px'
        this.Parent.ToolTip.style.top        = (TheContainerBounds.y + TheContainerBounds.height - 4) + 'px'
        
        if (TheCurrentTT !== this.Parent)
        {
            if (TheCurrentTT) TheCurrentTT.Hide()
            TheCurrentTT = this.Parent
        }
    })

    Base.MouseMoveEvents.push({ "Action": this.MouseMoveEvent, "Item": this.ToolTip })
}

MyToolTip.prototype.Hide = function()
{
    this.ToolTip.style.visibility = 'hidden'
    this.ToolTip.style.display    = 'none'
}

MyToolTip.prototype.MouseMoveEvent = function(item)
{
    if (item.style.visibility.toLowerCase() != 'visible') return

    var b = Sys.UI.DomElement.getBounds(item)

    b.x      = b.x      - 20
    b.y      = b.y      - 20
    b.height = b.height + 50
    b.width  = b.width  + 40

    if ((Base.MouseX + Base.ScrollX < b.x) || (Base.MouseX + Base.ScrollX > b.x + b.width) || (Base.MouseY + Base.ScrollY < b.y) || (Base.MouseY + Base.ScrollY > b.y + b.height)) 
    {
        item.style.visibility = 'hidden'
        item.style.display    = 'none'
    }
}

Sys.Application.add_load(function()
{
    var TheToolTip1 = new MyToolTip()
    TheToolTip1.Initialize($get('ctl00_TheTopControl_acctt'), 'Accommodation Locator', 19)
    var TheToolTip2 = new MyToolTip()
    TheToolTip2.Initialize($get('ctl00_TheTopControl_restt'), 'Restaurant Locator', 19)
    var TheToolTip3 = new MyToolTip()
    TheToolTip3.Initialize($get('ctl00_TheTopControl_attra'), 'Attractions Locator', 19)
    var TheToolTip4 = new MyToolTip()
    TheToolTip4.Initialize($get('ctl00_TheTopControl_mappp'), 'Map of Barbados', 19)
    var TheToolTip5 = new MyToolTip()
    TheToolTip5.Initialize($get('ctl00_TheTopControl_event'), 'Events Locator', 19)
//    var TheToolTip4 = new MyToolTip()
//    TheToolTip4.Initialize($get('sertt'), '<input type="text" value="search" class="sleek search" />', 3)
})

function SetClass(el, className)
   {
       if (el)
       {
           if ((Sys.Browser.agent == Sys.Browser.InternetExplorer) && (Sys.Browser.version < 8))
           {
               el.className = className
           }
           else
           {
               el.setAttribute("class", className)
           }
       }
   }
