﻿//--indicates the mouse is currently over a div 
var onDiv = false;
//--indicates the mouse is currently over a link
var onLink = false;
//--this is the ID of the timeout that will close the window if the user mouseouts the link 
var timeoutID;

function addBubbleMouseovers(mouseoverClass, NewClass) {
    $("#" + mouseoverClass).mouseover(function(event) {
        if (onDiv || onLink) {
            return false;
        }

        onLink = true;
        showBubble.call(this, event, mouseoverClass, NewClass);
    });

    $("#" + mouseoverClass).mouseout(function() {
        onLink = false;
        timeoutID = setTimeout(hideBubble, 150);
    });
}

function hideBubble() {
    clearTimeout(timeoutID);
    //--if the mouse isn't on the div then hide the bubble
    if (!onDiv) {
        $('#mytestbox').fadeOut('slow', function() {  });
        $('#mytest').fadeOut('slow', function() {  });
    }
}

function showBubble(event, mouseoverClass, NewClass) {

    $('#mytestbox').fadeOut('fast', function() {
        $('#mytest').fadeOut('fast', function() {
                $('#mytestbox').fadeOut('slow', function() {
                    $('#mytest').load('/hints.aspx?hint=' + mouseoverClass, function() {
                        $('#mytest').removeClass()
                        $('#mytest').addClass(NewClass)
                        var myvalue = $('#mytest').html();

                        if (String(myvalue).length < 2) {
                            $('#mytest').html("[" + mouseoverClass + "]");
                        }

                        var tPosX = $("#" + mouseoverClass).offset().left - $('.A1_logo').offset().left + $("#" + mouseoverClass).width() + 20;
                        var tPosY = $("#" + mouseoverClass).offset().top - 40;
                        $('#mytestbox').css({ left: tPosX, top: tPosY });
                        //            $('#mytest').corner("14px tl br");
                        $('#mytest').fadeTo('slow', 1, function() { });
                        $('#mytestbox').fadeTo('slow', 1, function() { });
                    });
                });
        });
    });
    //            alert(tPosX.toString() + " / " + tPosY.toString());
}

function keepBubbleOpen() {
    onDiv = true;
}

function letBubbleClose() {
    onDiv = false;

    hideBubble();
}

