/** ********************************
 * file:       main.js
 * author:     
 * created:    
 *
 * edit history:
 *
 *
 */
var levelOneActiveMenu = null;
var levelOneMenu;
var levelTwoActiveMenu = null;
var levelTwoMenu;
var hideTimerLevelOne;
var hideTimerLevelTwo;

function setmenu() 
{
	var arrLevelZeroItems = elemsByTag('a', elemById('leftnav'));
	for(var i=0; i < arrLevelZeroItems.length; i++)
	{
		arrLevelZeroItems[i].onmouseover = function () 
		{
			clearTimeout(hideTimerLevelOne);
			hideMenu();

			levelOneMenu = elemById('levelonemenudiv_' + this.id.substrAfter('_'));

			if (levelOneMenu)
			{
				var varCurrent = this;
				levelOneMenu.style.top = this.offsetTop - 180 + 'px';
				levelOneMenu.style.visibility = 'visible';

				levelOneMenuLinks = elemsChilds(levelOneMenu);
				for (var k=0; k<levelOneMenuLinks.length; k++)
				{
					levelOneMenuLinks[k].onmouseout = function () 
					{
						hideTimerLevelOne = setTimeout('hideMenu()',400);
					}
					levelOneMenuLinks[k].onmouseover = function () 
					{
						clearTimeout(hideTimerLevelOne);
					}
				}
				levelOneActiveMenu = levelOneMenu;

				/*Level Two Menu*/
				
				var arrLevelOneItems = elemsByTag('a', elemById('navlevelone'));
				for(var j=0; j < arrLevelOneItems.length; j++)
				{
					arrLevelOneItems[j].onmouseover = function () 
					{
						clearTimeout(hideTimerLevelTwo);
						hideMenu2();
						clearTimeout(hideTimerLevelOne);

						levelTwoMenu = elemById('leveltwomenudiv_' + this.id.substrAfter('_'));

						if (levelTwoMenu)
						{							
							levelTwoMenu.style.top = varCurrent.offsetTop + this.offsetTop - 186 + 'px';
							levelTwoMenu.style.left = this.offsetLeft + this.offsetWidth - 93 + 'px';
							levelTwoMenu.style.visibility = 'visible';
							
							levelTwoMenuLinks = elemsChilds(levelTwoMenu);
							for (var k=0; k<levelTwoMenuLinks.length; k++)
							{
								levelTwoMenuLinks[k].onmouseout = function () 
								{
									hideTimerLevelTwo = setTimeout('hideMenu2()',400);
								}
								levelTwoMenuLinks[k].onmouseover = function () 
								{
									clearTimeout(hideTimerLevelTwo);
									clearTimeout(hideTimerLevelOne);
								}
							}
							levelTwoActiveMenu = levelTwoMenu;
						}
					}
					arrLevelOneItems[j].onmouseout = function ()
					{
						levelTwoMenu = elemById('leveltwomenudiv_' + this.id.substrAfter('_'));
						hideTimerLevelTwo = setTimeout('hideMenu2()',400);
						//hideTimerLevelOne = setTimeout('hideMenu()',400);
					}	
					listen(document,'click',hideMenu2);
				}
				
				/*End of Level Two Menu*/

			}
		}
		arrLevelZeroItems[i].onmouseout = function ()
		{
			levelOneMenu = elemById('levelonemenudiv_' + this.id.substrAfter('_'));
			hideTimerLevelOne = setTimeout('hideMenu()',400);
		}	
		listen(document,'click',hideMenu);
	}
}


function elemById(id) {
   if (document.getElementById) {
      return document.getElementById(id);
   }
   else if (document.all) {
      return document.all[id];
   }
   else if (document.layers) {
      return document.layers[id];
   }
}
function elemsByTag(strTagname, elemParent) {
   var arrElems, listElems, i;

   if (isUndefined(elemParent)) {
      elemParent = document;
   }
   
   listElems = elemParent.getElementsByTagName(strTagname);
   
   arrElems = new Array(); 
   for (i = 0; i < listElems.length; ++i ) {
      arrElems[ arrElems.length ] = listElems[i];
   }
   return arrElems;
}
function elemsChilds(elemParent) {
  var listChilds, arrChilds, i;
  
  listChilds = elemParent.childNodes;
  
  arrChilds = new Array();
  for (i = 0; i < listChilds.length; i++) {
     if (isElement( listChilds[i] )) {
        arrChilds[ arrChilds.length ] = listChilds[i];
     }
  }
  return arrChilds;
}

function hideMenu() 
{
	if (levelOneActiveMenu)
	{
		levelOneActiveMenu.style.visibility = 'hidden';
	}
}

function hideMenu2() 
{
	if (levelTwoActiveMenu)
	{
		levelTwoActiveMenu.style.visibility = 'hidden';
	}
}

String.prototype.substrAfter = function (string) {
   return this.substr(this.indexOf(string) + string.length);
}