// image path variables
var currentSub=-1;			// keeps track of currently displayed sub menu
divpositions = new Array(); // keeps track of menu item positions

// Subexist is now generated in XSL
// subexist = new Array();		// keeps track of whether a menu item has a sub menu

function init(){
// Initialization function. Records vertical position of each Menu Item and stores it

  if (document.all){
    for (i = 0; i < numOfTops; i++){
    divpositions[i] = document.all['divTop' + i].offsetTop;
    document.all['divTop' + i].style.left = document.all['divTop' + i].offsetLeft + 5;
    }
  } else {
    for (i = 0; i < numOfTops; i++){
    divpositions[i] = document.layers['divTop' + i].top;
    }
  }

	if (subexist[buttonIDLookup[selsection]])
	{
		openSub(buttonIDLookup[selsection]);
	}
}

function openSub(i){
// Open Submenu function. Opens or closes selected submenu
// int i: submenu ID to be opened or closed

  if (i == currentSub){
    putBack();
    closeSubs();
    currentSub = -1;
  }
  else{
    putBack();
    closeSubs();
    layername = "divSub" + i;
    showLayer(layername);
    moveElement(layername, i);
	
	// Changes little cross image next to menu item
	/*
    if (document.all){
      document ['imgCross' + i].src = opencross.src;
    }
    else if (document.layers){
      document.layers['divTop' + i].document.images['imgCross' + i].src = opencross.src;
    }
	*/
    currentSub = i;
  }
}

function moveElement(object, i){
// Move menu item function. Moves main menu items vertically to make room for submenus
// string object: name of the submenu layer to be displayed
// int i: ID of submenu layer to be displayed

  if (document.all) shiftby = document.all[object].offsetHeight;
  else if (document.layers) shiftby = document.layers[object].document.height;
  for (j = (i+1); j < numOfTops; j++){
  if (document.all){
      document.all['divTop' + j].style.top = divpositions[j] + shiftby;
    }
  if (document.layers){
      document.layers['divTop' + j].moveBy(5, shiftby);
    }
  }
}

function putBack(){
// Puts all main menu items back in their original positions

  for (j=0; j < numOfTops; j++){
  if (document.all){
      document.all['divTop' + j].style.top = divpositions[j];
    }
  if (document.layers){
      document.layers['divTop' + j].moveToAbsolute(5, divpositions[j]);
    }
  }
}

function closeSubs(){
// Closes all submenus by hiding them

  if (document.all){
    // if (currentSub != -1) document ['imgCross' + currentSub].src = closecross.src;
    for (i = 0; i < numOfTops; i++){
      if (subexist[i] == 1) document.all['divSub' + i].style.visibility = 'hidden';
    }
  } else if (document.layers) {
    // if (currentSub != -1) document.layers['divTop' + currentSub].document.images['imgCross' + currentSub].src = closecross.src;
    for (i = 0; i < numOfTops; i++){
      if (subexist[i] == 1) document.layers['divSub' + i].visibility = 'hidden';
    }
  }
}

function showLayer(object) {
// Shows selected submenu layer
// string object: Name of submenu layer to be displayed

  if (document.all) {
    document.all[object].style.visibility = 'visible';
  }	else {
    document.layers[object].visibility = 'visible';
  }
}

function doNothing(){
// Placeholder function for javascript calls
}

