
  var activemenu = null;
  var timer;


  function navigateLink(template, page, linktarget){
    // dhtml menu uses location.href which doesn't really support
    // targets so... fake the new and ignore anything else
    var myurl = template + '?pg=' + page;
    if(linktarget=='_new'){
    	var all_options = "width=200,height=200,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,copyhistory=no";
    	var some_options = "width=400,height=300";
    	var other = "left=50,top=50,screenX=50,screenY=50";
    	window.open(myurl,'window'+linktarget,some_options)
    } else {
	location.href= myurl;
    }
  }
  
  function getPageOffsetLeft(el) {
    var x;
    // Return the x coordinate of an element relative to the page.
    x = el.offsetLeft;
    if (el.offsetParent != null)
      x += getPageOffsetLeft(el.offsetParent);
    return x;
  }


  function getPageOffsetTop(el) {
    var y;
    // Return the x coordinate of an element relative to the page
    y = el.offsetTop;
    if (el.offsetParent != null)
      y += getPageOffsetTop(el.offsetParent);
    return y;
  }

  function rolloversub(menu){
  	timer = clearTimeout(timer);
	menu.className = menu.className + "_rollover";   	
  }
  function rolloutsub(menu){
	menu.className = "submenu";
	// if you rollout and don't roll in, it will 
	// close after a quarter second
	timer = setTimeout('timeout()',200)
  }
  
  function timeout() {
	// close the active menu, we have a new active menu
	if(activemenu){
		var temp = activemenu; // remember the active
		closeactive(); // close submenu
		rollout(temp); // do rollout for old active 
	}
  }
  
  function opensub(id){
	menu = document.getElementById(id);
	// get the submenu (if exists)
	submenu = document.getElementById(id + 's');
	// position and show the submenu
	if(submenu) { 
		if(layout==1){
			var y = getPageOffsetTop(menu) + menu.offsetHeight;
			var x = getPageOffsetLeft(menu);
		 	submenu.style.top =  y + 'px';
		 	submenu.style.left = (x + 14) + 'px';	 	
			submenu.style.display="";
		} else {
			var x = getPageOffsetLeft(menu) + menu.offsetWidth;
			var y = getPageOffsetTop(menu);
			if (navigator.userAgent.indexOf("MSIE")>0) {
				if (navigator.userAgent.indexOf("Mac")>0) {
				    var x = (menu.clientLeft + 252);
				    var y = (menu.clientTop  + 164);
				}
			}
		 	submenu.style.top = y + 'px';
		 	submenu.style.left = (x + 14) + 'px';	 	
			submenu.style.display="";
		}
	}
	activemenu = menu;
  }

  function closeactive(){
  	if(activemenu){
		// get the submenu (if exists)
		submenu = document.getElementById(activemenu.id + 's');
		// hide the submenu
		if(submenu) { submenu.style.display="none" }	
		activemenu = null;
	}
  }

  function rollover(menu){
  	
  	timer = clearTimeout(timer);

  	// if this is an arrow, go get the menu
  	if (menu.className.substr(0,5) == "arrow" ){ 
  		menu = document.getElementById(menu.id.substr(0,menu.id.indexOf('a')));
  	}
  	
  	// if there is a submenu out
  	if (activemenu) {
  		if (menu == activemenu) {
  			return;
  		} else {
			// close the active menu, we have a new active menu
			var temp = activemenu; // remember the active
			closeactive(); // close submenu
			rollout(temp); // do rollout for old active
			timer = clearTimeout(timer);
	  	}
	 }
  	
  	// set the rollover class for menu
	menu.className = "menu_rollover"; 
	// get the arrow (if exists)
	arrow = document.getElementById(menu.id + 'a');
	// set the rollover class for arrow
	if(arrow){ arrow.className = "arrow_rollover"}
	
	// if there is a submenu, open it
	// if commented out, sub will open only when clicked
	opensub(menu.id);
	
  }

  function rollout(menu){ 
  	// if this is an arrow, go get the menu
  	if (menu.className.substr(0,5) == "arrow"){ 
  		menu = document.getElementById(menu.id.substr(0,menu.id.indexOf('a')))
  	}

  	if (activemenu) {
  		if (menu == activemenu) {
			timer = setTimeout('timeout()',200)
  			return;
	  	}
	 }

  	// set the rollout class for menu
	menu.className =  "menu";
	// get the arrow (if exists)
	arrow = document.getElementById(menu.id + 'a');
	// set the rollout class for arrow
	if(arrow){ arrow.className = "arrow"}
	timer = setTimeout('timeout()',200)
  }