/** Horizontal Menu Javascript (Image Swaps and Drop-down Menus) **/

var aButtons;
var aButtonsHover;
var aMenuObjects;
var indexCurrent;
var imgCurrent;
var visMenu;
var iTimer = 0;
var fCancel = false;

function hoverImage(obj, index) {
  showMenu(obj, index);
}

function leaveImage(obj, index) {
  /* obj.src = aButtons[index].src; */
  delayHideMenu();
}

function sizeFrame(frm) {
	/** Size iframe control to be as large as its children table                **/
	/** Note: this only needs to work in IE b/c Firefox has transparent IFRAMES **/
	with (frm) {
		try {
			var tbl = Document.getElementById('tblMenu');		
			style.height = tbl.clientHeight + 2;
			style.width = tbl.clientWidth + 2;
		} catch(ex) {
			/* Nothing */
		}
	}
}

function showMenu(obj, index) {
  /* Only allow one menu at a time */
  hideMenu();
  
  /* Setup button image 1st */
  obj.src = aButtonsHover[index].src;
  imgCurrent = obj;
  indexCurrent = index;
  
  /* Show menu second (if applicable) */
  if (aMenuObjects[index] != null) {
		sizeFrame(aMenuObjects[index]);
		visMenu = aMenuObjects[index];
    visMenu.style.visibility = 'visible';
  }
}

function delayHideMenu() {
	/* window.alert('delayHideMenu'); */
	if (!fCancel) {
		iTimer = window.setTimeout('hideMenu()', 400);
	}
}

function cancelHideMenu() {
	/* Tweak to ensure delayHideMenu is not called immediately afterwords */
	fCancel = true;
	window.setTimeout('fCancel = false;', 10);

	/* window.alert('cancelHideMenu'); */
  window.clearTimeout(iTimer);
  iTimer = 0;
}

function hideMenu() {
  /* window.alert('hideMenu'); */
  
  /* If there is a button activated, reset it */
  if (imgCurrent != null) {
    imgCurrent.src = aButtons[indexCurrent].src;
    imgCurrent = null;
    indexCurrent = -1
  }

	/* If there is a menu visible, hide it */
  if (visMenu != null) {
	  visMenu.style.visibility = 'hidden';
		visMenu = null;
	}
	
	cancelHideMenu();
}