var menu;
var theTop = 85; //distance from top to case studies box - may be altered in xmlhttpChange when Gloss receives content
var old = theTop;

window.onload = init; 
function init()
{	
	menu = new getObj('glossary');
	movemenu();
}
function closePopup(){
	document.getElementById('glossary').style.display='none';
}
function movemenu()
{
	if (window.innerHeight)
	{
		  pos = window.pageYOffset
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
		pos = document.documentElement.scrollTop
	}
	else if (document.body)
	{
		  pos = document.body.scrollTop
	}
	if (pos < theTop) pos = theTop;
	else pos += theTop;
	if (pos == old) //only move when stopped scrolling
	{
		menu.style.top = pos + "px";
	}
	old = pos;
	temp = setTimeout('movemenu()',300);
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}
/////			
function SendRequest(URL) {
  //If javascript is enabled add type to query string sent to php script.
  URLvar = URL.href + '&type=text'
  //If browser is IE, create Active X object
  if (window.ActiveXObject)
  {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    if (xmlhttp)
    {
		
      //Hook the event handler.
      xmlhttp.onreadystatechange=xmlhttpChange 
	  xmlhttp.open("GET", URLvar, false);
    }
    
  }
  //If browser is mozilla etc, create XMLHttpRequest object.
  else if (window.XMLHttpRequest)
  {
    xmlhttp=new XMLHttpRequest();
    //Hook the event handler
    xmlhttp.onload=xmlhttpChange
	xmlhttp.open("GET", URLvar, false);
  }

  //Prepare the call, http method=GET, URL is passed from a href below, false=asynchronous call
  //Finally send the call and begin the process.
    xmlhttp.send(null);
}
function xmlhttpChange(){
  // This handler is called 4 times for each state change of xmlhttp
  // States are: 0 uninitialized
  //      1 loading
  //      2 loaded
  //      3 interactive
  //      4 complete
  
  //When completed
  if (xmlhttp.readyState==4) {
    //Clear the div.
    document.getElementById('glossary_top_h2').innerHTML = "";
	
	
	document.getElementById('glossary_content').innerHTML ="";
	
	//Split the values returned separate by ,
	//This the places the returned values separately into an array
	var glossarytext = xmlhttp.responseText.split('~');
	
	//Then write the text from the DB into the example div.
	//Use responseText as the returned value is text and not XML.
	document.getElementById('glossary_top_h2').innerHTML = glossarytext[0];
	document.getElementById('glossary_content').innerHTML = glossarytext[1];

    //Show this division.
	document.getElementById('glossary').style.display = 'block'
	//check if it is too high for a 800x600 screen
	GlossDiv = document.getElementById('glossary');
	myHeight = GlossDiv.offsetHeight;
	if (myHeight > 410) {
		theTop = 5;
		GlossDiv.style.top = "5px";
	} else {
		theTop = 85;
	}
  }
}