var menuOpen = new Array(); // An array to contain the id and names of the menus already opened
var classOver = new Array(); // An array to contain the menu level that has the over class on it
var checkIt;
var DHTML = (document.getElementById || document.all || document.layers); // Try to get a boolean true for one of these, so that we know we can use dhtml

function show(name,lvl,obj)
{
	   if (!DHTML) return; // If the value is false, the the browser doesn't support dhtml so we drop out of the script
	   checkUserInput(); // Runs the function to see if there is a timer already in existence
	   if (menuOpen[lvl] && menuOpen[lvl] == name) return; // if the level passed in already exists AND it matches the name passed in, 
	   														//then the user has moved over an olready open menu so we do nothin and just exit the function
	   if (menuOpen[lvl]) // If we reached this stage then this must be a new menu but possibly on the same level. If the array holds a name on this level
	   {					// we need to close it as the user has moved onto a different menu
			   closeAll(lvl); // we lose all menus on that level
	   }
	   if (name) //if we have been passed the name of a new menu
	   {
			   var x = getObj(name);  //we open it  by calling the getObj function (so we know how the correctly reference it)
			   x.visibility = 'visible'; // then we simple make it visible
	   }
	   menuOpen[lvl] = name; // then set the array element contents corresponding to the menu level to the name of the menu open. if no name is given, then the array bocomse empty
	   // this next bit take care of the colour change when you move over a menu. it also provise the user a way of knowing which menu they came from
	   // in the case of multiple level menus
	   if (obj.parentNode) y = obj.parentNode; // first we search for the parent node, this one is for dom compliant browsers
	   else if (obj.parentElement) y = obj.parentElement; // this is if the user is using ie4
	   else return; // if neither of those worked then the browser doesnt support neither of the above (like ns4) so we cant apply the class and we exit
	   if (y.className) return; // if the parent node already has a class, then we dont need to do anything so we exit
	   y.className = 'over'; // if not, we apply the class
	   if (classOver[lvl]) classOver[lvl].className = ''; //if another link on the same level had the class applied we turn it off
	   classOver[lvl] = y; // then store the new object that has the class on it in the array
}

// To close the levels we go through in reverse order. We start at the level with the highest number and work backwards till we reach the level
// we've specified (usually lvl 1 as thats the top menu)
function closeAll(lvl)
{
	   for (i=menuOpen.length - 1; i>=lvl; i--)
	   {
			   if (menuOpen[i]) // if the array has a value at the number specified we close it by taking the object and setting it to hidden
			   {
					   var x = getObj(menuOpen[i]); //get the object of that name
					   x.visibility = 'hidden'; //set it to hidden
			   }
			   menuOpen[i] = null; //set the array element to null as we have just close the menu on that level
			   if (classOver[i]) // if an element of that levelno exists in the classOver array then that means it must have the class applied
			   {
					   classOver[i].className = ''; //so we turn it off
					   classOver[i] = null; // and set that element in the array to null as no menu with that lvl no is open and has no class
			   }
	   }
}

// This function determines if a timer is already running, if so it stops it and starts another one. The timers are used
// when moving over a different menu. There is a 2 second pause before a menu is closed.
function checkUserInput()
{
	   if (checkIt) clearTimeout(checkIt); // If checkit has a value, clear the timer
	   checkIt = setTimeout('closeAll(1)',3000); // Start a new timer, after 3000, invoke the closeAll function
}

// This function trys to evaluate 3 different DOM references for the same thing and returns an answer based on the browser
// i.e. if document.getElementByid is true then the function returns such. This function is used to determine how the elements
// should be referenced as each browser does it in different ways
function getObj(name)
{
 if (document.getElementById)
 {
   return document.getElementById(name).style;
 }
 else if (document.all)
 {
   return document.all[name].style;
 }
 else if (document.layers)
 {
   return document.layers[name];
 }
 else return false;
}

function openWin(theURL, winName, features)
{
	window.open(theURL, winName, features);
}

// Site specific stuff from now on
function imageSwapper(name,folder,src) {
if (document.images){ 
        eval('document.' + name + '.src = "' + folder + '/' + src + '"');
        }
}

function imageSwapper2(frame,name,folder,src) {
if (document.images){ 
        eval('top.frames[' + frame +'].document.' + name + '.src = "' + folder + '/' + src + '"');
        }
}

function initArray() {
	this.length = initArray.arguments.length;
	for (var i = 0; i < this.length; i++) {
		this[i] = initArray.arguments[i];
		}
}

function preloadImages() {
if (document.images) {
    if (typeof(document.WM) == 'undefined'){
      document.WM = new Object();
    }
    document.WM.loadedImages = new Array();
    // Loop through all the arguments.
    var argLength = preloadImages.arguments.length;
    for(arg=0;arg<argLength;arg++) {
      // For each arg, create a new image.
      document.WM.loadedImages[arg] = new Image();
      // Then set the source of that image to the current argument.
      document.WM.loadedImages[arg].src = preloadImages.arguments[arg];
    }
  }
}

function empty(kwords){
kwords.value=""
}

//added by steve 14/1/05
// JavaScript Document
/*
startList = function()
  {
  if (document.all && document.getElementById)
    {
    var node = document.getElementById("nav");
    
    AssignMenuEvents(node) ;
    }
  }

function AssignMenuEvents(pObject)
  {
  var node ;
  var vPreviousIndex ;
  
  for (i=0; i < pObject.childNodes.length; i++)
    {
    node = pObject.childNodes[i];

    if (node.tagName == "LI")
      {
      node.onmouseover=function()
                         {
                         this.className+=" over";
                         }

      node.onmouseout=function()
                         {
                         this.className=this.className.replace(" over", "");
                         }
      }

    if (node.childNodes.length > 0)
      {
      vPreviousIndex = i ;
      AssignMenuEvents(node);
      i = vPreviousIndex ;
      }
    }
  }


window.onload=startList;
*/