function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
addLoadEvent(lhninit);

function lhninit() {
	var lhn = $('lhn');
	
	var hrefsRaw = lhn.getElementsByTagName('A');

	var ulsRaw = lhn.getElementsByTagName('UL');

	var version = null;

	if (navigator.appVersion.indexOf("MSIE")!=-1){
	document.execCommand("BackgroundImageCache",false,true)
	temp=navigator.appVersion.split("MSIE")
	version=parseFloat(temp[1])
	}
		
	if (version==5.5) {
		var lis = lhn.getElementsByTagName('li');
		for (var j = 0; j < lis.length; j++)
		{
			lis[j].style.display = 'inline';
		}
	}

	for (var m = 0; m < hrefsRaw.length; m++)
	{
		if (hrefsRaw[m].id == 'lhnactive')
		{
			var active = m;
		}
	}
	lhnreset(active);
}

function lhnreset(active) {

	var lhn = $('lhn');
	
	var hrefsRaw = lhn.getElementsByTagName('A');

	var ulsRaw = lhn.getElementsByTagName('UL');

	for (var h = 0; h < hrefsRaw.length; h++)
	{
		if (hrefsRaw[h].parentNode.parentNode.parentNode.tagName == 'LI')
		{
			var sub = 'true';
		}
		else
		{
			var sub = 'false';
			var ultest = node_after(hrefsRaw[h]);
			if (ultest)
			{	
				if (ultest.tagName == 'UL')
				{
					var has = 'true';
				}
			}
			else
			{
				var has = 'false';
			}
		}

		if (h == active)
		{
			var act = 'true';
		}
		else
		{
			var act = 'false';
		}
		
		if (sub == 'false')
		{
			if (act == 'true')
			{
				hrefsRaw[h].parentNode.className = 'lhnactive';
				if (has == 'true')
				{	
					hrefsRaw[h].className = 'lhnactivehref';
					ultest.style.display = 'block';
				}
			}
			else
			{	
				hrefsRaw[h].parentNode.className = 'lhninactive';
				if (has == 'true')
				{	
					hrefsRaw[h].className = 'lhninactivehref';
					ultest.style.display = 'none';	
				}
			}
		}
		else if (sub == 'true' && act == 'true')
		{
			hrefsRaw[h].style.background = '#660000';
			hrefsRaw[h].parentNode.parentNode.style.display = 'block';
			var fc = first_child(hrefsRaw[h].parentNode.parentNode.parentNode);
			fc.className = 'lhnactivehref';
		}
		else if (sub == 'true' && act == 'false')
		{
			hrefsRaw[h].style.background = '#191919';
		}
	}

	hrefs = new Array();
	
	for (var i = 0; i < hrefsRaw.length; i++)
	{
		hrefsRaw[i].onkeydown = null;
		if (hrefsRaw[i].parentNode.parentNode.style.display != 'none')
		{
			hrefs.push(hrefsRaw[i]);
		}
	}

	for (var j = 0; j < hrefs.length; j++)
	{
		hrefs[j].id = 'lhnLink'+j;
		eval("hrefs[j].onkeydown = function(event) {return lhnarrows(event,"+j+");}");
	}

	for (var k = 0; k < ulsRaw.length; k++)
	{
		var lc = last_child(ulsRaw[k]);
		var fc = first_child(lc);
		fc.style.border = '0';
	}
}

function lhnarrows(e,id) {

	var code;
	if (!e) var e = window.event;
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;
	
	if (code == '38')
	{
		id=id-1;
		if ($('lhnLink'+id))
		{
			$('lhnLink'+id).focus();
		}
	}
	
	if (code == '40')
	{
		id=id+1;
		if ($('lhnLink'+id))
		{
			$('lhnLink'+id).focus();
		}
		
	}
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}

function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

function node_before( sib )
{
  while ((sib = sib.previousSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

function last_child( par )
{
  var res=par.lastChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.previousSibling;
  }
  return null;
}

function first_child( par )
{
  var res=par.firstChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.nextSibling;
  }
  return null;
}

