var loaded = 0, menu_max = 5; // change this line when adding/removing menu items

var data, txts, links, titles, i, container, ie, ns, ok, id, skipover;

function init(link_reset) {
  ie = ((document.all) ? 1 : 0);
  ns = ((document.layers) ? 1 : 0);
  ok = ie || ns;
  id = 0;
 
  if (!ok) return true;
  
  links  = new Array(menu_max);
  links[0] = "index.htm";  
  links[1] = "invest.htm";
  links[2] = "services.htm";  
  links[3] = "branch.htm";
  links[4] = "contact.htm"; 
  
  links[link_reset] = "";
  txts    = new Array(menu_max);
  txts[0] = wrapText("Licences", "index.htm#1") +
            wrapText("Finances", "index.htm#2");
 
  txts[1] = wrapText("Investment policy", "invest.htm#1") +
            wrapText("How to get credit", "invest.htm#2");

  txts[2] = wrapText("Crediting", "services.htm#1") +
            wrapText("Cash facilities", "services.htm#2") +
            wrapText("Currency operations", "services.htm#3") +
            wrapText("\"Client-Bank\" system", "services.htm#4") +
            wrapText("Deposit operations", "services.htm#5") +
            wrapText("Operations with securities", "services.htm#6") +
            wrapText("Services rendered to natural persons", "services.htm#7");


  txts[3] = "";
  txts[4] = "";
  
  titles = new Array(menu_max);
  titles[0] = "About the branch";
  titles[1] = "Investments";  
  titles[2] = "Services rendered";
  titles[3] = "Divisions";
  titles[4] = "Contact data";


  if (ie)
    container = document.all["Zcont"];
  else
    container = new Layer(window.innerWidth * 0.98); // damned buggy NC. 0.98 works well with 800 and 1024, but why?

  loaded  = 1;
  skipover= -1;
  return true;
}

function doTimeout(on) { // disallow cummulative timeouts
  if (on) {
    if (id) clearTimeout(id);
    id = setTimeout("hideMenu();", 1000);
  } else {
    if (id) clearTimeout(id);
    id = 0;
  }
}

function showMenu(index)
{
  if (!loaded || index == skipover) return true;
  doTimeout(0);
  for (i = 0, data = '', setHeader(), skipover = index; i < menu_max; i++) {
    if (i == index) {
      data += '<tr><td><div class="menu1"><a class="menu1-link" href="' + links[i] +
              '" onmouseout="doTimeout(1)">' + titles[i] + '</a></div><div class="menu2">' +
              txts[i] + '</div>';
    } else {
      if (links[i].length) {
        data += '<tr><td><div class="menu1"><a class="menu1-link" href="' + links[i] +
                '"' + ((txts[i].length) ? ' onmouseover="showMenu(' + i + ')"' : '') + '>' + titles[i] + '</a>';
      } else {
        data += '<tr><td bgcolor="#FFFDF3"><div class="menu1">' + titles[i] + '</div><div class="menu2">' + txts[i];
      }
    }
    data += '</div></td></tr><tr><td bgcolor="#003366" background="pic/back3.gif"><img src="pic/s.gif" width="1" height="1" border="0" alt=""></td></tr>';
  }
  data += '</table></td></tr></table>';

  if (ie) {
    container.innerHTML = data;
    container.style.visibility = 'visible';
  } else {
    container.document.open('text/html');
    container.document.writeln(data + '</div>');
    container.document.close();
    container.visibility = 'show';
  }
 
  return true;
}

function hideMenu() {
  doTimeout(0);
  if (ie)
    container.style.visibility = 'hidden';    
  else
    container.visibility = 'hide';
  skipover = -1;
  return true;
}

function setHeader() {
  if (!ie) data = '<img src="pic/s.gif" width="1" height="1" vspace="37" border="0" alt=""><br><div align="center">';
  data+= '<img src="pic/s.gif" width="1" height="1" vspace="11" border="0" alt=""><br><table width="85%" cellspacing="0" cellpadding="1" border="0">' + 
         '<tr><td><img src="pic/s.gif" width="1" height="1" vspace="8" hspace="300" border="0" alt=""></td></tr><tr><td>' +
         '<table width=253 cellpadding=0 cellspacing=0 border=0 bgcolor=white>';
}

function wrapText(text, link)
{
 var text1='';
 if (ns)
 {
  text=escape(text);
  for (i=0; i<text.length; i++)
  {
   if (text.charAt(i) == '%') {text1=text1+'0x';}
   else {text1=text1+text.charAt(i);}
  }
  text=eval(text1);
 // text=unescape(text);
 }
return '<a class="menu2-link" href="' + link + '" onmouseover="doTimeout(0)" onmouseout="doTimeout(1)">' + text + '</a><br>';
}


