var myMenu_path = new Array();
var myMenu_lang = 0;


function myMenu_constructPath(curMenu, depth, position)
{
  var result = false;

  if((curMenu[0][1] == myMenu_curChapNameId) && (depth >= 0))
  {
    myMenu_path = new Array(depth + 1);
    myMenu_path[depth] = position - 1;
    result = true;
  }
  else
  {
    for(var myMenu_i = 1; (result == false) && (myMenu_i < curMenu.length); ++myMenu_i)
    {
      if(myMenu_constructPath(curMenu[myMenu_i], depth + 1, myMenu_i) && (depth >= 0))
      {
        myMenu_path[depth] = position - 1;
        result = true;
      }
    }
  }

  return result;
}


function myMenu_initVars()
{
  myMenu_constructPath(myMenu, -1, 0);

  for(var myMenu_i = 0; myMenu_i < myMenu_langs.length; ++myMenu_i)
  {
    if(myMenu_langs[myMenu_i] == myMenu_langName)
    {
      break;
    }
    else
    {
      ++myMenu_lang;
    }
  }

// --- check certain vars to be safe

  if (typeof(myMenu_width)=="undefined")
	  myMenu_width = "100%";
  if (typeof(myMenu_align)=="undefined")
	  myMenu_align = "left";
}


function myMenu_constructMenu(curMenu, depth, position)
{
  var myMenu_fontIndex = (depth > myMenu_numFonts)? myMenu_numFonts: depth;
  var myMenu_linkExt = (((depth == myMenu_path.length) || (depth >= myMenu_numLevels)) && (myMenu_path[depth - 1] == (position - 1)))? "_active": "";
  var myMenu_linkClass = "link-" + myMenu_id + "-" + myMenu_fontIndex + myMenu_linkExt;
  var myMenu_fileNameExt = (curMenu[0][2] == "yes")? ".php": ".html";
  //var myMenu_fileName = (myMenu_langName != "_none")? "index_" + myMenu_langName: "index";
  var myMenu_fileName = (curMenu[0][4] != "")? curMenu[0][4] : "index";
  //alert(curMenu[0][4]);
  var myMenu_linkHref = (curMenu[0][0].substring(0, 8) != "_wplink_")? (myMenu_pathToRoot + curMenu[0][0] + myMenu_fileName + myMenu_fileNameExt): curMenu[0][0].substring(8, curMenu[0][0].length);
  var myMenu_linkTarget = (curMenu[0][3] == "_blank")? "_blank": "_self";

  if(depth == 1)
  {
  	document.write("<DIV CLASS=\"menuClass\">");
  }
  else
  {
  document.write("<DIV CLASS=\"menuClass2\">");
  }

  document.write("<A CLASS=\"" + myMenu_linkClass + "\" HREF=\"" + myMenu_linkHref + "\" TARGET=\"" + myMenu_linkTarget + "\">");

  var myMenu_txt = curMenu[0][myMenu_lang + 5];

  if(myMenu_txt.substring(0, 7) != "_wpimg_")
  {
    document.write(myMenu_txt);
  }
  else
  {
    var myMenu_curNameId = curMenu[0][1];
    var myMenu_curId = myMenu_curNameId.substring(myMenu_curNameId.indexOf(':') + 1);
    var myMenu_curImgBoth = myMenu_txt.substring(7, myMenu_txt.length);
    var myMenu_curImgSepIndex = myMenu_curImgBoth.indexOf(':');
    var myMenu_curImg, myMenu_curImgOver;

    if(myMenu_curImgSepIndex != -1)
    {
      myMenu_curImgOver = myMenu_curImgBoth.substring(myMenu_curImgSepIndex + 1, myMenu_curImgBoth.length);
      myMenu_curImg = (((depth == myMenu_path.length) || (depth >= myMenu_numLevels)) && (myMenu_path[depth - 1] == (position - 1)))? myMenu_curImgOver: myMenu_curImgBoth.substring(0, myMenu_curImgSepIndex);
    }
    else
    {
      myMenu_curImgOver = myMenu_curImgBoth;
      myMenu_curImg = myMenu_curImgBoth;
    }

    document.write("<IMG NAME=\'" + myMenu_curId + "\' SRC=\'" + myMenu_pathToRoot + "_wpimg/" + myMenu_curImg + "\' BORDER=\'0\' onMouseOver=\'document." + myMenu_curId + ".src=\"" + myMenu_pathToRoot + "_wpimg/" + myMenu_curImgOver + "\"\' onMouseOut=\'document." + myMenu_curId + ".src=\"" + myMenu_pathToRoot + "_wpimg/" + myMenu_curImg + "\"\'/>");
  }

  document.write("</A>");
  document.write("</DIV>");

  if((myMenu_path[depth - 1] == (position - 1)) && (depth < myMenu_numLevels))
  {
    myMenu_constructSubMenu(curMenu, depth + 1);
  }
}


function myMenu_constructSubMenu(curMenu, depth)
{
  document.write("<TABLE WIDTH=\"");
  document.write(myMenu_width);
  document.write("\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">");

  if((myMenu_layout == "horizontal") && (depth == 1))
  {
    document.write("<TR>");
  }

  if(curMenu.length > 1)
  {
    for(var myMenu_i = 1; myMenu_i < curMenu.length; ++myMenu_i)
    {
      if((myMenu_layout == "vertical") || (depth > 1))
      {
        if(myMenu_verticalSpacing > 0)
        {
          document.write("<TR><TD HEIGHT=\"" + myMenu_verticalSpacing + "\">");
          document.write("<IMG SRC=\"" + myMenu_pathToRoot + "images/blank.gif\" HEIGHT=\"" + myMenu_verticalSpacing + "\" WIDTH=\"1\"/>");
          document.write("</TD></TR>");
        }

        document.write("<TR>");
      }

      if(((myMenu_layout == "horizontal") && (myMenu_i > 1)) || (depth > 1))
      {
        document.write("<TD WIDTH=\"" + myMenu_horizontalSpacing + "\" HEIGHT=\"1\">");
        document.write("<IMG SRC=\"" + myMenu_pathToRoot + "images/blank.gif\" WIDTH=\"" + myMenu_horizontalSpacing + "\" HEIGHT=\"1\"/>");
        document.write("</TD>");
      }

      document.write("<TD VALIGN=\"TOP\" ALIGN=\"" + myMenu_align + "\">");

      myMenu_constructMenu(curMenu[myMenu_i], depth, myMenu_i);

      document.write("</TD>");

      if((myMenu_layout == "vertical") || (depth > 1))
      {
        document.write("</TR>");
      }
    }
  }

  if((myMenu_layout == "horizontal") && (depth == 1))
  {
    document.write("</TR>");
  }

  document.write("</TABLE>");
}


myMenu_initVars();
myMenu_constructSubMenu(myMenu, 1);
