function PullDownMenu(name)
{
  this.Name = name;
  this.Items = new Array();
  this.AddMenuItem = AddMenuItem;
  this.Parent = "";
  this.Show = Show;
  return this;
}

function AddMenuItem(caption, link, cursor, x, y)
{
  if (this.Parent == "")
    var mi = new CreateMenuItem(caption, link, cursor, this.Items.length, this, true, x, y);
  else
    var mi = new CreateMenuItem(caption, link, cursor, this.Items.length, this, false, x, y);
  this.Items.push(mi);
}

function CreateMenuItem(caption, link, cursor, count, obj, bool, x, y)
{
  this.Caption = caption;
  this.Cursor = cursor;
  this.Link = link;
  this.X = x;
  this.Y = y;
  this.Items = new Array();
  this.AddMenuItem = AddMenuItem;
  if (bool == true)
    this.Name = "menu" + count;
  else
    this.Name = obj.Name + count;
  this.Parent = obj;
  return this;
}

function Show()
{
  //toplevel
  if (this.Items.length > 0)
  {
//    document.write('			<div class="menuboxtop">');
//    for (var i = 0; i < this.Items.length; i++)
//      document.writeln('<a href="' + this.Items[i].Link + '" class="zero mainmenu" style="cursor: ' + this.Items[i].Cursor + '" onmouseover="DropDownMenu(\'' + this.Items[i].Name + 'box\', true)" onmouseout="DropDownMenu(\'' + this.Items[i].Name + 'box\', false)">' + this.Items[i].Caption + '</a>');
//    document.writeln('</div>');

    //secondlevel
    for (var i = 0; i < this.Items.length; i++)
    {
      if (this.Items[i].Items.length > 0)
      {
        document.write('<div id="' + this.Items[i].Name + 'boxout" class="zero" style="visibility: hidden; position: absolute; left: ' + this.Items[i].X+ 'px; top: ' + this.Items[i].Y + 'px">');

        document.write('<table onmouseover="DropDownMenu(\'' + this.Items[i].Name + 'box\', true)" onmouseout="DropDownMenu(\'' + this.Items[i].Name + 'box\', false)" class="menusubbox" cellspacing="0">');
        for (var j = 0; j < this.Items[i].Items.length; j++)
        {
          if (j == (this.Items[i].Items.length - 1))
          {
            document.write('<tr><td class="zero" name="' + this.Items[i].Name +'box"><a href="' + this.Items[i].Items[j].Link + '" class="menuitem" onmouseover="DropDownMenu(\'' + this.Items[i].Items[j].Name + 'box\', true)" onmouseout="DropDownMenu(\'' + this.Items[i].Items[j].Name + 'box\', false)" style="cursor: ' + this.Items[i].Items[j].Cursor + '; display: block; border-bottom: 0px solid">' + this.Items[i].Items[j].Caption + '<img class="iespan" src="../pictures/site/spacer.gif"></a></td></tr>');
          }
          else
          {
            document.write('<tr><td class="zero" name="' + this.Items[i].Name +'box"><a href="' + this.Items[i].Items[j].Link + '" class="menuitem" onmouseover="DropDownMenu(\'' + this.Items[i].Items[j].Name + 'box\', true)" onmouseout="DropDownMenu(\'' + this.Items[i].Items[j].Name + 'box\', false)" style="cursor: ' + this.Items[i].Items[j].Cursor + '; display: block;">' + this.Items[i].Items[j].Caption + '<img class="iespan" src="../pictures/site/spacer.gif"></a></td></tr>');
          }
        }
        
        document.write('</table></td></tr></table>');
        document.write('</div>');
      }
    }

    //thirdlevel
    for (var i = 0; i < this.Items.length; i++)
    {
      for (var j = 0; j < this.Items[i].Items.length; j++)
      {
        if (this.Items[i].Items[j].Items.length > 0)
        {
          document.write('<div id="' + this.Items[i].Items[j].Name + 'boxout" class="zero" style="visibility: hidden; position: absolute; left: ' + this.Items[i].Items[j].X+ 'px; top: ' + this.Items[i].Items[j].Y + 'px">');
          document.write('<table onmouseover="DropDownMenu(\'' + this.Items[i].Items[j].Name + 'box\', true);DropDownMenu(\'' + this.Items[i].Name + 'box\', true)" onmouseout="DropDownMenu(\'' + this.Items[i].Items[j].Name + 'box\', false);DropDownMenu(\'' + this.Items[i].Name + 'box\', false)" class="menusubbox" cellspacing="0">');
          for (var k = 0; k < this.Items[i].Items[j].Items.length; k++)
          {
            if (k == (this.Items[i].Items[j].Items.length - 1))
            {
              document.write('<tr><td class="zero" name="' + this.Items[i].Items[j].Name +'box"><a href="' + this.Items[i].Items[j].Items[k].Link + '" class="menuitem" style="cursor: ' + this.Items[i].Items[j].Items[k].Cursor + '; display: block; border-bottom: 0px solid">' + this.Items[i].Items[j].Items[k].Caption + '<img class="iespan" src="../pictures/site/spacer.gif"></a></td></tr>');
            }
            else
            {
              document.write('<tr><td class="zero" name="' + this.Items[i].Items[j].Name +'box"><div><a href="' + this.Items[i].Items[j].Items[k].Link + '" class="menuitem" style="cursor: ' + this.Items[i].Items[j].Items[k].Cursor + '; display: block">' + this.Items[i].Items[j].Items[k].Caption + '</a></td></tr>');
            }
          }
          document.write('</table></td></tr></table>');
          document.write('</div>');
        }
      }
    }

  }
}

function DropDownMenu(menubox, show)
{
  if (document.getElementById(menubox + "out") != null)
  {
    if (show)
    {
      document.getElementById(menubox + "out").style.visibility = "visible";
    }
    else
    {
      document.getElementById(menubox + "out").style.visibility = "hidden";
    }
  }
}

function swap(obj, type)
{
  if (obj.src.substring(obj.src.length - 22) == "righttopupexpanded.gif")
  {
    obj.src="../pictures/layout/righttopupexpandedhigh.gif";
  }
  else if (obj.src.substring(obj.src.length - 26) == "righttopupexpandedhigh.gif")
  {
    obj.src="../pictures/layout/righttopupexpanded.gif";
  }
  else if (obj.src.substring(obj.src.length - 20) == "righttopdownhigh.gif")
  {
    obj.src="../pictures/layout/righttopdown.gif";
  }
  else if (obj.src.substring(obj.src.length - 28) == "righttopdownexpandedhigh.gif")
  {
    obj.src="../pictures/layout/righttopdownexpanded.gif";
  }

  //Navigationspfeile (die dicken Pfeile)
  else if (obj.src.substring(obj.src.length - 22) == "rightbottomnavnext.gif")
  {
    obj.src="../pictures/layout/rightbottomnavnexthigh.gif";
  }
  else if (obj.src.substring(obj.src.length - 26) == "rightbottomnavnexthigh.gif")
  {
    obj.src="../pictures/layout/rightbottomnavnext.gif";
  }
  else if (obj.src.substring(obj.src.length - 11) == "navnext.gif")
  {
    obj.src="../pictures/layout/navnexthigh.gif";
  }
  else if (obj.src.substring(obj.src.length - 15) == "navnexthigh.gif")
  {
    obj.src="../pictures/layout/navnext.gif";
  }
  else if (obj.src.substring(obj.src.length - 11) == "navprev.gif")
  {
    obj.src="../pictures/layout/navprevhigh.gif";
  }
  else if (obj.src.substring(obj.src.length - 15) == "navprevhigh.gif")
  {
    obj.src="../pictures/layout/navprev.gif";
  }
  else if (obj.src.substring(obj.src.length - 10) == "navtop.gif")
  {
    obj.src="../pictures/layout/navtophigh.gif";
  }
  else if (obj.src.substring(obj.src.length - 14) == "navtophigh.gif")
  {
    obj.src="../pictures/layout/navtop.gif";
  }
  else if (obj.src.substring(obj.src.length - 14) == "navtopsite.gif")
  {
    obj.src="../pictures/layout/navtopsitehigh.gif";
  }
  else if (obj.src.substring(obj.src.length - 18) == "navtopsitehigh.gif")
  {
    obj.src="../pictures/layout/navtopsite.gif";
  }
  //Ende Navigationspfeile
  else
  {
    if (type)
      obj.src="../pictures/layout/righttopdownexpandedhigh.gif";
    else
      obj.src="../pictures/layout/righttopdownhigh.gif";
  }
}

//Ein- und Ausklappen des Boxen
//obj: Objekt zum Bild ändern
//type: mit Ansatz nach unten oder nicht
//id: des Display-Objekts
//borderid: Objekt, an dem die Top-Border geändert wird
function clickswap(obj, type, id, second)
{
  if ((obj.src.substring(obj.src.length - 22) == "righttopupexpanded.gif") || (obj.src.substring(obj.src.length - 26) == "righttopupexpandedhigh.gif"))
  {
    if (type)
      obj.src="../pictures/layout/righttopdownexpandedhigh.gif";
    else
      obj.src="../pictures/layout/righttopdownhigh.gif";
  }
  else
  {
    obj.src="../pictures/layout/righttopupexpandedhigh.gif";
  }
  
  swapobj = document.getElementById(id);
  if (swapobj.style.display == "none")
  {
    swapobj.style.display = "block";
    if (second)
    {
      swapobj = document.getElementById(id + "topleft");
      swapobj.src = "../pictures/layout/lefttopexpanded.gif";
    }
  }
  else
  {
    swapobj.style.display = "none";
    if (second)
    {
      swapobj = document.getElementById(id + "topleft");
      swapobj.src = "../pictures/layout/lefttop.gif";
    }
  }
}

function changesmilie(obj)
{
  file = obj.options[obj.options.selectedIndex].value;
  if (file == "knuschel")
    file += ".png";
  else
    file += ".gif";
  document.getElementById("smilie").src = "../pictures/forum/" + file;
  document.getElementById("link").innerHTML = obj.options[obj.options.selectedIndex].value;
  
}

function toposting()
{
  file = document.getElementById("selectbox").options[document.getElementById("selectbox").options.selectedIndex].value;
  obj = document.getElementById("body");
  obj.value = obj.value + "[smilie:" + file + "]";

}


////////////////////////////////////////////////////////////////////////////////
// function for showing the tutorial-pictures in their real size              //
////////////////////////////////////////////////////////////////////////////////
function showPicture(obj)
{
  src = obj.src;
  src = src.substring(src.lastIndexOf("/") + 1, src.length);
  // große Version anzeigen
  if (src.indexOf("-small") > -1)
  {
	  src = src.substring(0, src.indexOf("-small")) + src.substring(src.length - 4, src.length);
    obj.src = "../pictures/" + src;
  }
  // kleine Version anzeigen
  else
  {
	  src = src.substring(0, src.length - 4) + "-small" + src.substring(src.length - 4, src.length);
	  obj.src = "../pictures/thumbnails/" + src;
  }
}

function insertScript()
{
  insertScriptByNode(document.getElementById("navigation").firstChild, true);
}

function insertScriptByNode(node, fromTop)
{
  do
  {
    if (isUL(node.firstChild))
    {
      node.onmouseover = showSubMenu;
      node.onmouseout = hideSubMenu;
      // position initially at the left side to avoid horizontal scrollbar in ie7
      isUL(node.firstChild).style.left = '0px';
      count = insertScriptByNode(isUL(node.firstChild).firstChild, false);
      if (fromTop)
      {
        ul = isUL(node.firstChild);
        ulWidth = ul.offsetWidth;
        li = ul.firstChild;
        while (li)
        {
          if (li.tagName == 'LI')
          {
            li.style.width = ulWidth + "px";
          }
          li = li.nextSibling;
        }
      }
    }
    node = node.nextSibling;
  } while(node);
}

function isUL(node)
{
  do
  {
    if(node)
      node = node.nextSibling;
    if((node) && (node.nodeName == "UL"))
      return node;
  } while (node);
  return false;
}

function showSubMenu()
{
  var node = isUL(this.firstChild);
  node.style.visibility = "visible";
  node.style.backgroundColor = "transparent";

  nodeLI = this;
  nodeUL = nodeLI.parentNode;
  testNode = nodeUL.parentNode;
  if (testNode.tagName == 'LI')
  {
    node.style.top = '-1px';
    node.style.left = nodeLI.offsetWidth + 'px';

    offHeight = nodeLI.offsetHeight;
    nodeAdj = node.firstChild;
    readjust = false;
    while (nodeAdj)
    {
        if ((nodeAdj.tagName == 'LI') && (Math.abs(nodeAdj.offsetHeight - offHeight) > 2))
        {
          readjust = true;
          break;
        }
        nodeAdj = nodeAdj.nextSibling;
    }
    if (!readjust)
      return;
    widthUL = node.offsetWidth;
    nodeAdj = node.firstChild;
    readjust = false;
    readjusted = false;
    i = 0;
    while ((nodeAdj) || (readjust))
    {
      // cancel after 200 runs
      i++;
      if (i > 200)
        break;

      if ((nodeAdj == node.firstChild) && (readjusted))
        readjusted = false;
      if (nodeAdj.tagName == 'LI')
      {
        // reset item width to needed width
        do
        {
          readjust = false;
          nodeAdj.style.width = widthUL + 'px';
          if (Math.abs(nodeAdj.offsetHeight - offHeight) > 2)
          {
            readjust = true
            readjusted = true;;
            widthUL += 5;
          }
        } while (readjust);
      }
      // start over again if an element was adjusted to more than the standard width
      if (readjusted)
        nodeAdj = node.firstChild;
      else
        nodeAdj = nodeAdj.nextSibling;
    }
  }
}

function hideSubMenu()
{
  isUL(this.firstChild).style.visibility = "hidden";
}

window.onload = insertScript;
