  var strTempString = '';


// get custom headline
  var strCustomHeadLine = parent.frames[0].document.getElementById('headline').innerHTML;
  var intAddCustomHeadLineBefore = 0;
  var strAddCustomHeadLineBefore = parent.frames[0].document.getElementById('headlinepos').innerHTML;



// get number of desired headline position
  var j=0;
// while pos. counter is not on a ","
  while (strAddCustomHeadLineBefore.charAt(j) != ',')
  {
// add char
    strTempString += strAddCustomHeadLineBefore.charAt(j);
// increase pos. counter
    j++;
  }
// return position of headline
  intAddCustomHeadLineBefore = parseInt(strAddCustomHeadLineBefore);



// set current-openend-cat-flag to 9999 (this means no category is opened)
  var currOpenCat = 9999;

// get number of categories from hidden frame
  var numOfCat;
  var strMenuOrder = parent.frames[0].document.getElementById('hidden').innerHTML;
  strTempString = '';
  var i=0;
// while pos. counter is not on a ","
  while (strMenuOrder.charAt(i) != ',')
  {
// add char
    strTempString += strMenuOrder.charAt(i);
// increase pos. counter
    i++;
  }
// return number of categories
  numOfCat = parseInt(strTempString);
// increase pos. counter (because it's definitely on a ",")
  i++;

// get number of sub-categories from hidden frame
  var numOfSubCat = new Array(numOfCat);
// go through all categories
  for (var j=0; j<numOfCat; j++)
  {
// reset temp string
    strTempString='';
  // while pos. counter is not on a ","
    while (strMenuOrder.charAt(i) != ',')
    {
    // add char
      strTempString += strMenuOrder.charAt(i);
    // increase pos. counter
      i++;
    }
  // return number of sub-category
    numOfSubCat[j] = parseInt(strTempString);
  // increase pos. counter (because it's definitely on a ",")
    i++;
  }

// create array for information about category entries
  var strCat = new Array(numOfCat);
// create array for information about sub-category entries
  var strSubCat = new Array(numOfCat);

// creates and fills category info array and outputs category div tags
// containing function links, then calls function to fill subcat array
  function fBuildMenu()
  {
  // category text
  // go through all categories
    for(var i=0; i<strCat.length; i++)
    {
    // create new info array for each category
      strCat[i]=new Array(2);
    // fill info array
      strCat[i][0] = 'javascript:fCatOpen(' + i + ')';
      strCat[i][1] = 'buttons/kat' + i + '.gif';

    // output div tags for categories
      document.write('<div id="catId' + i + '" name ="catName' + i + '" width="100%">');


//////////////////////////////////////////////////////////////
    // if desired category, add custom headline
      if (i == intAddCustomHeadLineBefore)
        document.write(strCustomHeadLine);
//////////////////////////////////////////////////////////////


      document.write('<a href="javascript:fCatOpen(' + i + ')"><img src="' + strCat[i][1] + '" border="0"></a><br>');
      document.write('</div>');
    }
    fFillSubCatArrays();
  }

// creates and fills sub-category array
  function fFillSubCatArrays()
  {
  // go through all categories
    for (var c=0; c<strSubCat.length; c++)
    {
    // create new array for each sub-category
      strSubCat[c]=new Array(numOfSubCat[c]);
    // go through all sub-categories
      for (var s=0; s<strSubCat[c].length; s++)
      {
      // create new info array for each sub-category
        strSubCat[c][s]=new Array(2);
        strSubCat[c][s][0] = 'pages/page' + c + '_' + s + '.htm';
        strSubCat[c][s][1] = 'buttons/subkat' + c + '_' + s + '.gif';
      }
    }
  }

// opens category and outputs sub-category links (changes content of category div tag)
  function fCatOpen(catNum)
  {
  // if opened, close old category
    if (currOpenCat != 9999)
    {

//////////////////////////////////////////////////////////////
    // set closeoutput variable
      var strCloseOutput = '';
    // if desired category, add custom headline
      if (currOpenCat == intAddCustomHeadLineBefore)
        strCloseOutput = strCustomHeadLine;
      strCloseOutput += '<a href="javascript:fCatOpen(' + currOpenCat + ')"><img src="' + strCat[currOpenCat][1] + '" border="0"></a><br>';
//////////////////////////////////////////////////////////////
      document.getElementById('catId' + currOpenCat).innerHTML = strCloseOutput;

//      document.getElementById('catId' + currOpenCat).innerHTML = '<a href="javascript:fCatOpen(' + currOpenCat + ')"><img src="' + strCat[currOpenCat][1] + '" border="0"></a><br>';
    }
  // new text for current category div tag
    var strNewCatText;

//////////////////////////////////////////////////////////////
  // if desired category, add headline, else only add image
    if (catNum == intAddCustomHeadLineBefore)
    {
      strNewCatText = strCustomHeadLine;
    } else
    {
      strNewCatText = '';
    }
//////////////////////////////////////////////////////////////


  // category header is no link any more, just an image
    strNewCatText += '<img src="' + strCat[catNum][1] + '" alt="' + strCat[catNum][2] + '" border="0"><br>';

  // list sub-category links
    for (var s=0; s<numOfSubCat[catNum]; s++)
    {
      strNewCatText += '&nbsp;&nbsp;<a href="' + strSubCat[catNum][s][0] + '" target="rechts"><img src="' + strSubCat[catNum][s][1] + '" border="0"></a><br>';
    }
  // update current opened cat flag
    currOpenCat = catNum;
  // output to category div tag
    document.getElementById('catId' + catNum).innerHTML = strNewCatText;
  // output cat page in right frame
    parent.frames['rechts'].location.href = 'pages/kat_' + catNum + '.htm';
  }

