function maake(ta) {
  var te = new Array();
  te[0] = 0;
  for (i = 1; i < a.length; i++) {
    te[i] = te[i-1] + ta[i-1] + 1;
  }
  return te;
}
function change (num) {
  document.getElementById("menu").firstChild.getElementsByTagName("tr")[e[num-1]].firstChild.bgColor = "#5e5e5e";
}

function back (num) {
  if (d != num) {
    document.getElementById("menu").firstChild.getElementsByTagName("tr")[e[num-1]].firstChild.bgColor = "#a4a4a4";

 }
}
function oldcollapse (num) {
  if (num != 0) {
    for (i = 1; i <= a[num-1]; i++) {
      document.getElementById("menu").firstChild.getElementsByTagName("tr")[e[num-1]+i].style.display="none";
    }
    obj = "pijl" + num;
    if (document.getElementById(obj) != null) document.getElementById(obj).src = "/images/pijlR.gif";
  }
}
function collapse (num,exp) {
  if (mutex == 0) {
    mutex = 1;
    if (num != 0) {
      d = exp;
      if (num != exp) back(num);
      else d = 0;
      Gaantal = a[num-1]+1;
      Gnum = num;
      Gexp = exp;
      mcollapse();
      obj = "pijl" + num;
      if (document.getElementById(obj) != null) document.getElementById(obj).src = "/images/pijlR.gif";
    } else {
      expand(exp);
    }
  }
}
function mcollapse () {
  Gaantal = Gaantal - 1;
  if (Gaantal != 0) {
    document.getElementById("menu").firstChild.getElementsByTagName("tr")[e[Gnum-1]+Gaantal].style.display="none";
    setTimeout("mcollapse()",30);
  } else {
    expand(Gexp);
  }
}
function expand (num) {
  if (b == num) {
    b = 0;
    d = 0;
    mutex = 0;
  } else {
    d = num;
    Gaantal = a[num-1]+1;
    Gnum = num;
    mexpand();
    obj = "pijl" + num;
    if (document.getElementById(obj) != null) document.getElementById(obj).src = "/images/pijlB.gif";
    b = num;
  }
}
function mexpand () {
  Gaantal = Gaantal - 1;
  if (Gaantal != 0) {
    document.getElementById("menu").firstChild.getElementsByTagName("tr")[e[Gnum-1]+Gaantal].style.display="";
    setTimeout("mexpand()",30);
  } else {
    mutex = 0;
  }
}
function subback (num,subnum) {
  document.getElementById("menu").firstChild.getElementsByTagName("tr")[e[num-1]+subnum].firstChild.bgColor = "#98B2CC";
}
function subchange (num,subnum) {
  document.getElementById("menu").firstChild.getElementsByTagName("tr")[e[num-1]+subnum].firstChild.bgColor = "#E5EBF2";
}
function init () {
  for (j = 1; j <= c; j++) {
    oldcollapse(j);
    back(j);
    for (k = 1; k <= a[j-1]; k++) {
      subback(j,k);
    }
  }
}

function delay(gap){ // gap is in millisecs
  var then,now;
  then=new Date().getTime();
  now=then;
  while((now-then)<gap) {
    now=new Date().getTime();
  }
}
