var xmlDoc;
var xmlReq;
var saveLastKey = '';
var Letter;

function loadGlossaryXML(){
//load xml file
// code for IE
Letter = 'A';
if (window.ActiveXObject)
  {
  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.load("glossary.xml");
  getWords();
  }
// code for Mozilla, etc.
else if (navigator.userAgent.indexOf('Konq')!=-1)
  {
  xmlDoc= document.implementation.createDocument("","",null);
  xmlDoc.load("glossary.xml");
  xmlDoc.onload=getWords;
  }
else if (window.XMLHttpRequest)
  {
  	//alternate XMLHTTP request - Gecko, Safari 1.2+ and Opera 7.6+
	xmlReq = new XMLHttpRequest();
	xmlReq.onreadystatechange = new Function( 'if( xmlReq.readyState == 4 && xmlReq.status < 300 ) { setXML(xmlReq.responseXML); }' );
	xmlReq.open("GET", "glossary.xml", true);
	xmlReq.send(null);
	return true;

  }
else
  {
  alert('Your browser cannot handle this script');
  }
  
}

function setXML(obj){
	//alert(obj);
	xmlDoc = obj;
	getWords();
}

function getWords(){
	var newTag;
	var tagCount;
	var fullTag;
	var wordList;
	var meaningList;
	var catList;
	var columnPos =0;
	var rowCount =0;
	var wordPos;
	
	saveLastKey = '';
	//alert('GetWords');
	catList = xmlDoc.getElementsByTagName("category");
	wordList = xmlDoc.getElementsByTagName("word");
	meaningList = xmlDoc.getElementsByTagName("meaning");
	tagCount = wordList.length;
	//if (Letter=='A') {alert(tagCount);}
	fullTag='';
	//alert(tagCount);
	wordPos=80;
	columnPos=20;
	//alert(Letter);
	for (i=0; i<tagCount; i++){ 
		if (catList[i].firstChild.nodeValue==Letter){
			newTag=' <span style="position:absolute;top:'+wordPos+'px;left:'+ 
										columnPos+'px;width:200px" class="keyword" onmouseup="showMeaning(this);" id="'+
											wordList[i].firstChild.nodeValue+'">' + 
											wordList[i].firstChild.nodeValue + '</span><br/>'+
											'<span class="keywordMeaning" style="display:none" onmouseup="hideMeaning();" id="m'+wordList[i].firstChild.nodeValue+'"><span class="keywordMeaningText" >' + 		
											'<b>'+wordList[i].firstChild.nodeValue+'</b><br/><br/>'+meaningList[i].firstChild.nodeValue + '<br/><br/>(Click to close)</span></span> ';
			fullTag=fullTag+newTag;
			//alert(newTag);
			wordPos=wordPos+15;
			rowCount++;
			if (rowCount>22)
			{
				rowCount=0;
				wordPos=80;
				columnPos=columnPos+200;	
			}
		}
	}
	
	document.getElementById("glossarywordlist").innerHTML=fullTag;
}

function displayGlossary(){
	
	
}

function showWords(objid){
	
	Letter=objid;
	
	getWords();
	
}

function showMeaning(obj){
	
	
	hideMeaning();
	document.getElementById('m'+obj.id).style.display='block';
	
	saveLastKey=obj.id;
}
function hideMeaning(){
	
	
	if (saveLastKey!='') {
		document.getElementById('m'+saveLastKey).style.display='none';
		
	}
}
function altXMLLoad(oURL){
}

