﻿$(document).ready(function() 
{
    RemoveHrefAndAddOnClick();
});

function RemoveHrefAndAddOnClick()
{
    jQuery("#tx_content .tag").each(
    function (i) 
    {
        var glossaryWord = this.getAttribute("href", 2);
        this.onclick = function(index)
        {
            var anchor = jQuery(this);
            ToolTip(i, glossaryWord.substring(6), anchor.offset().left, anchor.offset().top);
        };
        this.removeAttribute("href");
    });
}

function ToolTip(index, glossaryWord, x, y)
{    
    if(jQuery(".tool_tip" + index).length > 0)
    {
        return null;
    }
    
    var newdiv = document.createElement("div");
    newdiv.id = "tool_tip";
    newdiv.className = "tool_tip" + index;
    newdiv.style.display = "none";
    newdiv.style.position = "absolute";
    newdiv.style.top = y - 115 + "px";
    newdiv.style.left = x + "px";
    
    jQuery.ajax({
        type: "POST", 
        url: GetRoot() + "Handlers/Glossary.ashx?document=" + glossaryWord,
        dataType:"html",
        data:{},
        success: function(html){
            newdiv.innerHTML = '<b class="xtop"><b class="xb1"></b><b class="xb2"></b><b class="xb3"></b></b><div class="tool_tip_content"><table><tr><td>'+html+'</td><td valign="top"><div class="tool_tip_close" onclick="RemoveDiv(' + index + ')"></div></td></tr></table></div><b class="xbottom"><b class="xb5"></b><b class="xb4"></b><b class="xb1"></b></b>';
          }          
    });
       
    jQuery("#tx_content").append(newdiv);
    jQuery(newdiv).fadeIn("slow"); 
}

function RemoveDiv(index)
{
    jQuery(".tool_tip" + index).fadeOut("slow", function() { jQuery(".tool_tip" + index).remove(); });
}