var item_id = new Array();
var mObj = new Array();
function TREEMENU() {
//--------------------------------------------------------------------------
// Configuration
//--------------------------------------------------------------------------

  this.width = '189';                // menu width (pixels)
  this.bgColor = "#FFFFFF";            // menu background color
  this.autoClose = true;                // close folders automatically (true or false)

  this.itemMargin = 0;                // item margin (pixels)
  this.itemPadding = 0;                // item padding (pixels)
  this.itemColor = "#FFFFFF";            // item font color
  this.itemBGColor = "#1A57C2";            // item background color
  this.itemBGColor1 = "#1A57C2";            // item background color for level-one-items
  this.itemFont = "Verdana, Arial, Helvetica";    // item font family (CSS spec.)
  this.itemSize = 10;                // item font size (pixels)
  this.itemBold = false;                // item bold font (true or false)
  this.itemWrap = true;                // item word wrap (true or false)

  this.iconWidth = 11;                // icon width (pixels)
  this.iconHeight = 13;                // icon height (pixels)
  this.iconClosed = "/images/tree/plus.gif";        // icon closed (path)
  this.iconOpen = "/images/tree/minus.gif";            // icon open (path)
  this.iconPoint = "/images/tree/point.gif";        // icon point (path)
  this.imgBlank = "/images/tree/blank.gif";            // blank image (path)
  this.bg_sub2  = "#F5F7FB";

//--------------------------------------------------------------------------
// Functions
//--------------------------------------------------------------------------

  this.mNr = 0;
  this.actItem = -1;
  this.targetWindow = 0;
  this.items = new Array();
  
  this.last_knot = null;


  this.entry = function(level, text, url, target,curr_open)
  {
    var i = this.items.length;
    this.items[i] = new makeItem(level, text, url, target, curr_open);
  }

  this.getObj = function(id)
  {
    var obj;
    if(document.getElementById) obj = document.getElementById(id);
    else if(document.all) obj = document.all[id];
    return obj;
  }

  this.jump = function(item)
  {
    this.openMenu(item);
    if(this.items[item].url)
    {
        if(this.items[item].target)
        {
            if(this.items[item].target.indexOf('parent.') == -1 && this.items[item].target.indexOf('top.') == -1)
            {
                if(this.targetWindow && !this.targetWindow.closed) this.targetWindow.location.href = this.items[item].url;
                else this.targetWindow = window.open(this.items[item].url, 'targetWindow');
                this.targetWindow.focus();
            }
            else eval(this.items[item].target + '.location.href = "' + this.items[item].url + '"');
        }
        else document.location.href = this.items[item].url;
    }
  }

  this.openMenu = function(item) {
    if(this.items[item].knot) this.actItem = item;
    this.newMenu();
  }

  this.closeMenu = function(item)
  {
    this.actItem = -1;
    if(this.items[item].knot)
    {
        this.items[item].icon = this.iconClosed;
        for(var i = item+1; i < this.items.length && this.items[i].level > this.items[item].level; i++)
        {
            if(this.items[i].level > 1) this.items[i].view = false;
        }
    }
    this.newMenu();
  }

  this.viewMenu = function(item)
  {
    var icon = this.items[item].icon;
    if(icon == this.iconOpen) this.closeMenu(item);
    else this.openMenu(item);
  }

  this.setItems = function() {
    var i, showlevel;
    if(this.autoClose && this.actItem >= 0) {
      if(this.items[this.actItem].level <= 1) {
        for(i = 0; i < this.items.length; i++) {
          if(this.items[i].level > 1) this.items[i].view = false;
        }
      }
    }
    for(i = 0; i < this.items.length; i++) {
      if(i < this.items.length-1 && this.items[i+1].level > this.items[i].level) {
        this.items[i].icon = this.items[i+1].view ? this.iconOpen : this.iconClosed;
        this.items[i].knot = true;
      }
      else this.items[i].icon = this.iconPoint;
    }
    if(this.actItem >= 0) {
      showLevel = this.items[this.actItem].level + 1;
      this.items[this.actItem].icon = this.iconOpen;
      for(i = this.actItem+1; i < this.items.length && this.items[i].level >= showLevel; i++) {
        if(this.items[i].level == showLevel) this.items[i].view = true;
      }
    }
  }

  this.content = function(item) {
    var text = '';
    if(item == null) item = 0;
    if(this.items[item].view) {
      text += '<table border=0 cellspacing=' + this.itemMargin + ' cellpadding=0 width=189>';

      if(this.items[item].knot) {
          if (this.items[item].level == 1) {
              text += '<tr><td width="20"><img alt="" src="/images/' + (this.items[item].target ?'l2.gif':'l2-1.gif') + '" name="r2" border="0"></td>';
              text += '<td width="170"  style="cursor:pointer;" colspan="2" ' + (this.items[item].target ? 'bgcolor="#E7EEF8"' : '') + 'onclick="javascript:mObj[' + this.mNr + '].viewMenu(' + item + ')" onMouseOut="MM_swapImgRestore(); ' + (this.items[item].target ?'':'this.style.backgroundColor=\'#FFFFFF\';') + '" onMouseOver="MM_swapImage(\'r2\',\'\',\'/images/l2.gif\',1); ' + (this.items[item].target ?'':'this.style.backgroundColor=\'#E7EEF8\';') + '"><h2>';
              text += (this.itemBold ? '<b>' + this.items[item].text + '</b>' : this.items[item].text);
              text += '</h2></td>';
              text += '</tr>';
          } else
          if (this.items[item].level == 2) {
              text += '<tr vAlign=top bgcolor="'+this.bg_sub2+'"><td width="20" style="background: url(/images/l1_submenu.gif) left top repeat-y;">&nbsp;</td>';
              text += '<td width="14" align=left>';
              text += '<img src="' + this.items[item].icon + '" border=0' + ' width=' + this.iconWidth + ' height=' + this.iconHeight + ' onclick="javascript:mObj[' + this.mNr + '].viewMenu(' + item + ')" style="cursor:hand;">';
              text += '</td>';
              text += '<td>';
              text += '<h3 style="cursor:pointer;" onclick="javascript:mObj[' + this.mNr + '].viewMenu(' + item + ')">'+
                  (this.itemBold ? '<b>' + this.items[item].text + '</b>' : this.items[item].text) + '</h3>';
              text += '</td>';
              text += '<td width="14" align="left">&nbsp;</td>';
              text += '</tr>';
              text += '<tr height="7" bgcolor="'+this.bg_sub2+'"><td style="background: url(/images/l1_submenu.gif) left top repeat-y;"></td><td colspan="2" style="font-size:2px; background: url(/images/div_subrubric.gif) left top repeat-x; ">&nbsp;</td><td></td></tr>';
              
              this.last_knot = this.items[item].target;
          }
                  
      }
    else
      {
          if (this.items[item].level == 3) {
              text += '<tr vAlign=middle><td width=20 align=right style="background: url(/images/l1_subsubmenu.gif) left top repeat-y;">&nbsp;</td>';
              text += '<td width="14">';
              text += '<img src="' + this.imgBlank + '" border=0' + ' width="14"  height=' + this.iconHeight + '></td>';
              text += '<td width="161">';
              text += '<div><ul>';
              if (this.items[item].target == "true")
                  text += '<li class="current">' + this.items[item].text + '</li>'; else
                  text += '<li><a href="'+ this.items[item].url +'">' + this.items[item].text + '</a></li>';
              text += '</ul></div>';
              text += '</td>';
              text += '<td width="14" align="left">&nbsp;</td></tr>';
          }
      }
      text += '</table>';
    }
    item++;
    if(item < this.items.length) text += this.content(item);
    return text;
  }
  
  this.newMenu = function() {
    var obj = this.getObj('divTreeMenu' + this.mNr);
    if(obj) {
      this.setItems();
      obj.innerHTML = this.content();
    }
  }

  this.buildContainer = function() {
    var lnk1 = '.cssLink' + this.mNr;
    var lnk2 = '.cssLinkHilight' + this.mNr;
    document.write('<style> .cssMenu' + this.mNr + ' { ' +
        'width: ' + this.width + 'px; ' +
        (this.bgColor ? 'background-color: ' + this.bgColor + '; ' : '') +
        '} ' + lnk1 + ', ' + lnk1 + ':visited, ' + lnk1 + ':active { ' +
        'color: ' + this.itemColor + '; ' +
        'font-family: ' + this.itemFont + '; ' +
        'font-size: ' + this.itemSize + 'px; ' +
        'text-decoration: none; ' +
        '} ' + lnk1 + ':hover { ' +
        'text-decoration: underline; ' +
        '} ' + lnk2 + ', ' + lnk2 + ':visited, ' + lnk2 + ': </style>' +
        '<div id="divTreeMenu' + this.mNr + '" class="cssMenu' + this.mNr + '"></div>');
  }

  this.create = function()
  {
    this.mNr = mObj.length;
    if(mObj[this.mNr] = this)
    {
        this.buildContainer();
        this.newMenu();
    }
    else alert("Could not create menu!");
  }

  //------------------------------------------------------------------------
  // Arguments: position level 1, [position level 2], ... [position level n]
  // Example:   jumpTo(1, 3, 2, 1) ==> this jumps to menu item 1.3.2.1
  //
  this.jumpTo = function()
  {
    var pos, aktPos;
    var item = 0;
    var level = 1;
    for(var i = 0; i < this.items.length; i++)
    {
        if(this.items[i].level > 1) this.items[i].view = false;
    }
    this.actItem = -1;
    this.setItems();
    if(!arguments) var arguments = this.jumpTo.arguments;
    for(i = 0; i < arguments.length; i++, level++)
    {
        pos = arguments[i];
        for(aktPos = 0; item < this.items.length && aktPos < pos; item++)
        {
            if(this.items[item].level == level) aktPos++;
        }
        if(aktPos == pos)
        {
            item -= 1;
            this.openMenu(item);
        }
        else break;
    }
    if(item) this.jump(item);
  }
  //------------------------------------------------------------------------
}

function makeItem(level, text, url, target,curr_open)
  {
    this.level = level;
    this.text = text;
    this.url = url;
    this.target = target;
    this.icon = '';
    this.view = ( level <= 1) ? true : curr_open;
    this.knot = false;
  }

function newLocation(texturl)
{
   window.location=texturl
}