function genMenu(pageid, dir) {
    for (i in menu) {
        mitem = menu[i];
        id = mitem[0];
        title = mitem[1];

        if (mitem.length == 3) { // there is submenu
            submenu = mitem[2];

            document.writeln(" \
                    <div class = 'item' id = '" + id + "' \
                    onmouseover = 'showSubMenu(\"" + id + "\")' \
                    onmouseout = 'hideSubMenu(\"" + id + "\")'> \
                    <div class = 'static' id = 'link-" + id + "'>" + title + "</div>");

            // create submenu
            document.writeln("<div class = 'submenu' id = 'sub-" + id + "'>");
            for (j in submenu) {
                subitem = submenu[j];
                subid = subitem[0];
                subtitle = subitem[1];
                filename = dir + id + '/' + subid;
                subid = id + '-' + subid;
                document.writeln(" \
                        <div class = 'subitem' id = '" + subid + "' \
                        onmouseover = 'activateMenuItem(\"" + subid + "\")' \
                        onmouseout = 'deactivateMenuItem(\"" + subid + "\")'> \
                        <a id = 'link-" + subid + "' href = '" + filename + ".html'>- " + subtitle + "</a> \
                        </div>");
            }
            document.writeln("</div>");
            document.writeln("</div>");
        } else {
            // there is no submenu
            document.writeln(" \
                    <div class = 'item' id = '" + id + "' \
                    onmouseover = 'activateMenuItem(\"" + id + "\")' \
                    onmouseout = 'deactivateMenuItem(\"" + id + "\")'>");
            document.write("<a ");
            if (pageid == id) {
                document.write("class = 'active' ");
            }
            document.writeln("id = 'link-" + id + "' href = '" + dir + id + ".html'>" + title + "</a>");
            document.writeln("</div>");
        }
    }

  //FLOATING MENU
  agent = this.navigator.userAgent;
  if (agent.indexOf('Opera') == -1) {
  //comment this line to disable floating menu
   floatingMenuOn();  
  } 
}


/* Script by: www.jtricks.com
 * Version: 20060303
 * Latest version:
 * www.jtricks.com/javascript/navigation/floating.html
 */


function floatingMenuOn() {

  target_x = 0;
  if ( agent.indexOf('Firefox') > -1 || agent.indexOf('Opera') > -1) {
    target_y = 126;
  } else {
    target_y = 119;
  }

  has_inner = typeof(window.innerWidth) == 'number';
  has_element = document.documentElement && document.documentElement.clientWidth;

  fm_shift_x = 0;
  fm_shift_y = 0;
  fm_next_x = 0;
  fm_next_y = 0;

   var fm_id='menu';
   floating_menu =
      document.getElementById
      ? document.getElementById(fm_id)
      : document.all
        ? document.all[fm_id]
        : document.layers[fm_id];
  
  floating_menu.style.position='relative';
  
  compute_shifts();
  if (document.layers)
  {
      // Netscape 4 cannot perform init move
      // when the page loads.
      fm_next_x = 0;
      fm_next_y = 0;
  }
  else
  {
      fm_next_x = fm_shift_x + target_x;
      fm_next_y = fm_shift_y + target_y;
      move_menu();
  }
  float_menu();
}


function move_menu()
{
    if (document.layers)
    {
        floating_menu.left = fm_next_x;
        floating_menu.top = fm_next_y;
    }
    else
    {
        floating_menu.style.left = fm_next_x + 'px';
        floating_menu.style.top = fm_next_y + 'px';
    }
}

function compute_shifts()
{
    fm_shift_x = has_inner
        ? pageXOffset
        : has_element
          ? document.documentElement.scrollLeft
          : document.body.scrollLeft;
    if (target_x < 0)
        fm_shift_x += has_inner
            ? window.innerWidth
            : has_element
              ? document.documentElement.clientWidth
              : document.body.clientWidth;

    fm_shift_y = has_inner
        ? pageYOffset
        : has_element
          ? document.documentElement.scrollTop
          : document.body.scrollTop;
    if (target_y < 0)
        fm_shift_y += has_inner
            ? window.innerHeight
            : has_element
              ? document.documentElement.clientHeight
              : document.body.clientHeight;
}

function float_menu()
{
    var step_x, step_y;

    compute_shifts();

    step_x = (fm_shift_x + target_x - fm_next_x) * .07;
    if (Math.abs(step_x) < .5)
        step_x = fm_shift_x + target_x - fm_next_x;

    step_y = (fm_shift_y + target_y - fm_next_y) * .07;
    if (Math.abs(step_y) < .5)
        step_y = fm_shift_y + target_y - fm_next_y;

    if (Math.abs(step_x) > 0 ||
        Math.abs(step_y) > 0)
    {
        fm_next_x += step_x;
        fm_next_y += step_y;
        move_menu();
    }

    setTimeout('float_menu()', 20);
}

/*
 * Script END
 */

