// glossary.js
// Pull data from glossary.xml file and produce a cool popup with the term definitions

var closing = true;
var currentSpan = null;
var currentTerm = "";
var currentDefinition = "";
var currentTermId = "";

function defineTerm(obj)
{
	//if(currentSpan == obj)
	//{
	if (currentSpan != null) return;

	//}
	//else
	//{
	//	closing = true;
	//	killDefinition();
	//	closing = false;
	//}
	
	currentSpan = obj;
	currentTermId = obj.getAttribute("termid");
	
	if(document.all)
		currentTerm = obj.innerText;
	else
		currentTerm = obj.textContent;
	
	$(function(){
		$.get("xml/glossary.xml",{},function(xml) {
			$('entry',xml).each(function(i) {				
				var foundTerm = $(this).attr("id");	
						
				if(foundTerm == currentTermId)				
				{
					var founddef = $(this).find("definition").text();					
					var content = '';
					content += '<u>' + currentTerm + '</u>';
					content += '<span id="definition" style="font-size:11px;" class="definition" onmouseover="onDefinition();" onmouseout = "closeDefinition();">';
					content += '<b><u>';
					content += $(this).find("term").text();
					content += '</u></b>:<br>';
					content += founddef;
					content += '<br><br>';
					content += '<a href="glossary.aspx">View Glossary</a>';
					content += '</span>';
					obj.innerHTML = content;
					obj.className = "";
				}
			});
		});	
	});	
}

function closeDefinition()
{
	closing = true;
	setTimeout("killDefinition()",100); 
}

function onDefinition(obj)
{
	closing = false;
	defineTerm(obj);
}

function killDefinition()
{
	if(!closing) return;
	if(currentSpan == null) return;
	currentSpan.className = "term";
	if(document.all)
		currentSpan.innerText = currentTerm;
	else
		currentSpan.textContent = currentTerm;
		
	currentSpan = null;
}