/*
filename:    buttonmenu.js
purpose:     make an entire li clickable
*/

function getById(id)
{
   if (document.getElementById)
      return document.getElementById(id);
   else if (document.all)
	   return document.all[id];
   else if (document.layers)
   	return document.layers[id];
   else
      return false;
} // end FUNCTION

function initialise_menu()
{
   // initialise
   if (!document.getElementsByTagName)
      return true;
   // fetch lis
   var lis = document.getElementsByTagName('LI');
   if (!lis)
      return true;
   // loop through
   for (c=0; c<lis.length; c++)
   {
      if (lis[c].className.search(/link/) != -1)
      {
         // ie6 support for li:hover
         lis[c].onmouseover = function() { this.className += ' hover'; };
         lis[c].onmouseout = function() { this.className = this.className.replace('hover', ''); };
         // deal with click
         lis[c].onclick = select_link;
      }
   }
} // end FUNCTION

function select_link(e)
{
   // fetch event and event target info (QUIRKSMODE)
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;

	// itterate up until we find li; through max 5
	count = 0;
	while (targ.tagName != 'LI' && count < 5)
	{
	   targ = targ.parentNode;
	   count++;
	}
	// got li?
	if (targ.tagName != 'LI')
	   return true;

   // find link
   var links = targ.getElementsByTagName('A');
   if (!links || links.length < 1)
      return true;

   // action
   document.location = links[0].href;
   return false;
} // end FUNCTION


