function MenuItem(text, url, target, maus, imgs)
{
  this.text     = text;
  this.url      = url;

  if (target)
  {
    this.target = target;
  }
  else
  {
    this.target = frm_target;
  }

  this.maus     = maus;
  this.imgs     = imgs;
  this.submenu  = null;
  this.expanded = false;
  this.makeSubmenu = makeSubmenu;
}


function makeSubmenu(menu)
{
  this.submenu = menu;
}


function Menu()
{
  this.items = new Array();
  this.addItem = addItem;
}


function addItem(item)
{
  this.items[this.items.length] = item;
}


var doc = parent.frames[frm_menu].document;
var abstand;
var grafik = new Array();
var indizes = new Array();


//-----------------------------------------------------
// Baumstruktur zeichnen, Ordner auf und zu
//-----------------------------------------------------


function draw_tree(menu)
{
  abstand = 0;
  doc.open('text/html', 'replace');
  doc.write('<HTML><HEAD><LINK REL=STYLESHEET HREF="'+css_file+'" TYPE="text/css"></HEAD><BODY background="pap7-1.gif" bgproperties="fixed">');  
  doc.write('<TABLE><TR><td colspan="2"><a href="start.htm" target="content"><img SRC="logo200.gif" ALT="Brüngsberger Reiterstube" border="0"></a></td></TR>');  
  doc.write('<tr><td height="50">&nbsp;</td></tr></TABLE>');  

  // -- [Ab hier Kopfbereich]
  doc.write('<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>');
  show_folder_content(menu);
  doc.write('</TABLE>');
  
  // -- [Ab hier Fußbereich]

  doc.write('</BODY></HTML>');
  doc.close();
  return false;
}

function show_folder_content(menu)
{
  for (var i = 0; i < menu.items.length; i++)
  {
    indizes[abstand] = i;
    draw_folder(menu.items[i], (i == menu.items.length - 1));
  }
}


function draw_folder(item, last, schalter)
{
  var frm = "parent.frames['" +frm_source+ "']";
  var cmd = frm + ".draw_tree(" + frm + ".menu)";
  var ref = frm + ".menu.items[" + indizes[0] + "]";
  var i, img, more;

  doc.write('<TR VALIGN=TOP><TD>');

  for (i = 0; i < abstand; i++)
  {
    if (grafik[i])
      doc.write('<IMG SRC="'+img_path+'menu_linie.gif" WIDTH=32 HEIGHT=32 ALIGN="left" BORDER=0 VSPACE=0 HSPACE=0>');
    else
      doc.write('<IMG SRC="'+img_path+'menu_leer.gif" WIDTH=32 HEIGHT=32 ALIGN="left" BORDER=0 VSPACE=0 HSPACE=0>');
    more = false;
  }

  if (item.submenu)
    for (i = 0; i < item.submenu.items.length; i++)
    {
      if (item.submenu.items[i].submenu != null) more = true;
    }

  if (!more)
  {
    if (last)
      img = img_path+"menu_was_3.gif";
    else
      img = img_path+"menu_was_2.gif";

    doc.write('<img src="' + img + '" WIDTH=32 HEIGHT=32 ALIGN="left" BORDER=0 VSPACE=0 HSPACE=0>');
  }

  for (i = 1; i <= abstand; i++)
  {
    ref += ".submenu.items[" + indizes[i] + "]";
  }

  // -- [Menüpunkte und Verweise ausgeben]
  if (item.submenu)
  {
    if (item.expanded)
      doc.write('<A HREF="#" onClick="' + ref + '.expanded = false; return ' + cmd + ';"' +
	             ' onMouseOver="window.status=\'' +txt_open+ '\';return true" onMouseOut="window.status=\'\'">');
    else
      doc.write('<A HREF="#" onClick="' + frm + '.open_tree(false);' + ref + '.expanded = true; return ' + cmd + ';"' +
	           ' onMouseOver="window.status=\'' +txt_closed+ '\';return true" onMouseOut="window.status=\'\'">');
  }
  else
  {
    doc.write('<A HREF="' + item.url + '" TARGET="' + item.target +
	           '" onMouseOver="window.status=\'' +item.maus+ '\';return true" onMouseOut="window.status=\'\'">');
  }

  // -- [Ordner auf/zu - Grafiken zeichnen (+/-)]
  if (more)
  {
    if (item.expanded)
    {
      if (last)
        img = img_path+"menu_minus_2.gif";
      else
        img = img_path+"menu_minus_1.gif";
    }
    else
    {
      if (last)
        img = img_path+"menu_plus_2.gif";
      else
        img = img_path+"menu_plus_1.gif";
    }

    doc.write('<IMG SRC="' + img + '" WIDTH=32 HEIGHT=32 ALIGN="left" BORDER=0 VSPACE=0 HSPACE=0>');
  }

  // -- [Ordner auf/zu - Grafiken zeichnen (Ordner)]
  if (item.submenu)
  {
    if (!item.imgs)
    {
      if (item.expanded)
        img = img_path+icon_open;
      else
        img = img_path+icon_closed;
    }
    else
      img = img_path+item.imgs; // Benutzerdefinierte Grafik
  }
  else
  {
    img = img_path+icon_default; // default Grafik
    if (item.imgs)
      img = img_path+item.imgs;
  }
	
  // -- [Grafiken für die Einträge bestimmen]
  doc.write('<IMG SRC="' + img + '" WIDTH=32 HEIGHT=32 ALIGN="left" BORDER=0 VSPACE=0 HSPACE=0>');
  if (item.submenu)
  {
    if (item.url != "")
    {
      doc.write('</A>');
      doc.write('<A HREF="' + item.url + '" TARGET="' + item.target +
	             '" onMouseOver="window.status=\'' +item.maus+ '\';return true" onMouseOut="window.status=\'\'">');
    }
  }
  doc.write('&nbsp;' + item.text + '</A>');
  doc.write('</TD></TR>');

  // -- [Ende]
  if (item.expanded)
  {
    if (!last)
      grafik[abstand] = true;
    else
      grafik[abstand] = false;

    abstand++;
    show_folder_content(item.submenu);
    abstand--;
  }
  else
    grafik[i] = false;
}

function do_tree(wert,was)
{
  for (var i=0; i < eval(was+".length"); i++)
  {
    if (eval(was+"["+i+"].submenu"))
    {
      eval(was+"["+i+"].expanded="+wert);
      do_tree(wert,was+"["+i+"].submenu.items");
   }
  }
}

function open_tree(wert)
{
  var was = "parent.frames['"+frm_source+"'].menu.items";
  do_tree(wert,was);
  draw_tree(menu);
}

function do_searchtree(arg,was)
{
  var found;
  var retvalue=false;
  var txt, txtUpper;
  
  for (var i=0; i < eval(was+".length"); i++)
  {
    if (eval(was+"["+i+"].submenu"))
    {
      found = do_searchtree(arg,was+"["+i+"].submenu.items");
      if (found)
      {
        retvalue = found;
        eval(was+"["+i+"].expanded=true");
      }
    }

    txt = eval(was+"["+i+"].text");
    txtUpper = txt.toUpperCase();
    if (txtUpper.search(arg) >= 0)
    {
      retvalue = true;
    }
  }
  
  return retvalue;
}

function search_tree(wert)
{
  var was = "parent.frames['"+frm_source+"'].menu.items";
  do_tree(false,was);

  do_searchtree(wert.toUpperCase(), was);
  
  draw_tree(menu);
}

