// mouse over (on) and mouseoff(off) color values
var oncolor = "#ff0000";
var offcolor = "#ffffff";

function changecolor(divname,colorname) {
stopall();
document.getElementById(divname).style.backgroundColor = colorname;
}

// show or hide DIV element
function showhide(divname,state) {
document.getElementById(divname).style.visibility = state;
}

// variables that hold the value of the currently active (open) menu
var active_submenu1 = null;
var active_submenu2 = null;
var active_menuelem = null;
var active_topelem = null;

// function closes all active menus and turns back to 'off' state
function closeallmenus() {
if(active_submenu1 != null) {
  showhide(active_submenu1,'hidden');
  }
if(active_submenu2 != null) {
  showhide(active_submenu2,'hidden');
  }
if(active_menuelem != null) {
  changecolor(active_menuelem,offcolor);
  }
if(active_topelem != null) {
  changecolor(active_topelem,offcolor);
  }
}

// the menu close timeout variable
var menu_close_timeout = 0;

// delay in miliseconds until the open menus are closed
var delay = 300;

// function calls the closeallmenus() function after a delay
function closeall() {
menu_close_timeout = setTimeout('closeallmenus()',delay);
}

// stop all timeout functions (stops menus from closing)
function stopall() {
clearTimeout(menu_close_timeout);
}

// function controls submenus (
// name submenu1 : submenu that has to be shown
// name submenu2 : submenu at second level that has to be shown
// name menuelem : if submenu2 is shown, the elem in submenu1 that has to be opened
// name topelem; name of top element
// a parameter is null if not applicable)
function controlsubmenu(submenu1,submenu2,menuelem,topelem) {

stopall();
closeallmenus();
if (submenu1 != null) {
  showhide(submenu1,'visible');
  active_submenu1 = submenu1;
  }
if (submenu2 != null) {
 showhide(submenu2,'visible');
 active_submenu2 = submenu2;
  }
if (menuelem != null) {
 changecolor(menuelem,oncolor);
 active_menuelem = menuelem;
 }
if (topelem != null) {
 changecolor(topelem,oncolor);
 active_topelem = topelem;
 }
}


function initialize() {
closeallmenus();
stopall();
}
