var mObj = new Array();

function TREEMENU(openAll) {
//----------------------------------------------------------------------------------------------------
// Configuration
//----------------------------------------------------------------------------------------------------

  this.width = 128;                                 // menu width (pixels)
  this.autoClose = true;                            // close level-one-folders automatically (true or false)
  this.itemTopMargin = 0;
  this.itemMargin = 0;                              // item margin (pixels)
  this.itemPadding = 2;                             // item padding (pixels)
  this.itemColor = "#000000";                       // item font color
  this.itemBGColor = "#FFFFCC";                     // item background color
  this.itemBGColor1 = "#CFCBB1";                    // item background color for level-one-items D8C8F7
  this.itemFont = "Tahoma";                          // item font family (CSS spec.)
  this.itemSize = 10;                               // item font size (pixels)
  this.itemTopSize = 11;                            // item font size (pixels)
  this.itemBold = true;                             // item bold font (true or false)
  this.itemWrap = true;                             // item word wrap (true or false)
  this.itemActive = "red";                          // active item font color
  this.itemActiveUnderline = false;                 // active item underline (true or false)

  this.iconWidth = 16;                              // icon width (pixels)
  this.iconHeight = 16;                             // icon height (pixels)
  this.iconClosed = "closed.gif";                   // icon closed (path)
  this.iconClosedHilight = "closed_hilight.gif";    // icon closed hilight (path)
  this.iconOpen = "open.gif";                       // icon open (path)
  this.iconOpenHilight = "open_hilight.gif";        // icon open hilight (path)

  this.OB_Top=0;				    //position from top (px)
  this.OB_Left=0;				    //position from left (px)
  this.OB_Margin=0;				    //top and bottom margins between icons and borders
  this.OB_ButtonHeight=28;                          //button height
  this.OB_TopButtonHeight=36;

//----------------------------------------------------------------------------------------------------
// Functions
//----------------------------------------------------------------------------------------------------

  this.mNr = 0;
  this.curItem = -1;
  this.hilightItem = -1;
  this.targetWindow = 0;
  this.items = new Array();    

  if(openAll == null) openAll = false;
  this.openAll = openAll;

  this.entry = function(level, text, url, target, icongif, icongifHilight, onClick) {
    var i = this.items.length;
    this.items[i] = new makeItem(level, text, url, target, icongif, icongifHilight, onClick, this.openAll);
 }


  this.getObj = function(id) {
    var obj;
    if(document.getElementById) obj = document.getElementById(id);
    else if(document.all) obj = document.all[id];
    return obj;
  }

  this.setHilight = function(item) {

    if(this.hilightItem >= 0) {
      var i = this.hilightItem;
      if(this.items[i].icon == this.iconOpenHilight) this.items[i].icon = this.iconOpen;
      else if(this.items[i].icon == this.iconClosedHilight) this.items[i].icon = this.iconClosed;
      else if(this.items[i].icon == this.items[i].icongifHilight) this.items[i].icon = this.items[i].icongif;
    }
    
    this.hilightItem = item;
    if(this.items[item].icon == this.iconOpen) this.items[item].icon = this.iconOpenHilight;
    else if(this.items[item].icon == this.iconClosed) this.items[item].icon = this.iconClosedHilight;
    else if(this.items[item].icon == this.items[item].icongif) this.items[item].icon = this.items[item].icongifHilight;
  }

  this.jump = function(item) { 
    this.setHilight(item);
    this.openMenu(item);

    if(this.items[item].onClick) eval(this.items[item].onClick);
    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].node) {
      this.curItem = item;
      this.items[item].icon = (item == this.hilightItem) ? this.iconOpenHilight : this.iconOpen;
    }
    this.newMenu();
  }

  this.closeMenu = function(item) {
    this.curItem = -1;
    if(this.items[item].node) {
      this.items[item].icon = (item == this.hilightItem) ? this.iconClosedHilight : this.iconClosed;
    }
    this.newMenu();
  }

  this.viewMenu = function(item) {
    var icon = this.items[item].icon;
    if(icon == this.iconOpen || icon == this.iconOpenHilight) this.closeMenu(item);
    else this.openMenu(item);
  }

  this.content = function(item) {
    var text = '';
    var bgc = (this.items[item].level <= 1) ? this.itemBGColor1 : this.itemBGColor;
    var vartemp = (this.items[item].level <= 1) ? this.itemTopMargin : this.itemMargin ;
    var vartemp2 = (this.items[item].level <= 1) ? 1 : 0 ;
    text +=  '<table border=' + vartemp2 + ' cellspacing=' + vartemp + 
             ' cellpadding=0 width=100% style="border-collapse: separate"><tr>' + 
             '<td ' + (bgc ? ' bgcolor=' + bgc  : '') + '>' + 
             '<table border=0 cellspacing=0 cellpadding=' + this.itemPadding + '><tr valign=center>';
   
    if(this.items[item].level > 1) {
      for(i = 1; i < this.items[item].level; i++) {
        text += '<td>&nbsp;</td>';
      }
    }
    var vartemp = (this.items[item].level <= 1) ? this.OB_ButtonHeight : this.OB_TopButtonHeight ;
    text += '<div style="cursor:hand"><td height="'+ vartemp +'">';
    if(this.items[item].node) text += '<a href="javascript:mObj[' + this.mNr + '].viewMenu(' + item + ')">';
    text += '<img src="menuimg/' + this.items[item].icon + '" border=0' + 
            ' width=' + this.iconWidth +
            ' height=' + this.iconHeight +
            '> ' +
            '</a></td></div>' +
            '<td ' + (this.itemWrap ? '>' : ' nowrap>') +
            '<a href="javascript:mObj[' + this.mNr + '].jump(' + item + ')" class="' +
            ((item == this.hilightItem) ? 'cssLinkHilight' : 'cssLink') + this.mNr + '">' +
            (this.itemBold && this.items[item].level <= 1 ? '<b><DIV STYLE="font-size:' + this.itemTopSize +'px">' + this.items[item].text + '</div></b>' : this.items[item].text) +
            '</a></td></tr></table></td></tr></table>';
    return text;
  }

  this.newMenu = function() {
    var menu = '';
    var i, j;
    var obj = this.getObj('divTreeMenu' + this.mNr);
    if(obj) {
      if(this.autoClose && this.curItem >= 0) {
        if(this.items[this.curItem].level <= 1) {
          for(i = 0; i < this.items.length; i++) {
            if(i != this.curItem && this.items[i].node && this.items[i].level == 1) {
              this.items[i].icon = this.iconClosed;
            }
          }
        }
      }
      for(i = 0; i < this.items.length; i++) {
        menu += this.content(i);
        if(this.items[i].icon == this.iconClosed || this.items[i].icon == this.iconClosedHilight) {
          for(j = i+1; j < this.items.length && this.items[j].level > this.items[i].level; j++);
          i = j - 1;
        }
      }
      obj.innerHTML = menu;
    }
  }

  this.buildContainer = function() {
    var lnk1 = '.cssLink' + this.mNr;
    var lnk2 = '.cssLinkHilight' + this.mNr;

    document.write('<style> .cssMenu' + this.mNr + ' { ' +
                   'width: ' + this.width + 'px; ' +
                   '} ' + 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 + ':active { ' +
                   'text-decoration: none; color: ' + this.itemActive + '; ' +
                   'font-family: ' + this.itemFont + '; ' +
                   'font-size: ' + this.itemSize + 'px; ' +
                   (this.itemActiveUnderline ? 'text-decoration: none' : '') +
                   '}</style>' +
                   '<div id="divTreeMenu' + this.mNr + '" class="cssMenu' + this.mNr + '"  style="position:absolute;top:'+ this.OB_Top +';left:'+ this.OB_Left +'" ></div>');
  }

  this.createStructure = function() {
    for(i = 0; i < this.items.length; i++) {
      if(!this.items[i].icon) {
        if(i < this.items.length-1 && this.items[i+1].level > this.items[i].level) {
          this.items[i].icon = this.openAll ? this.iconOpen : this.iconClosed;
          this.items[i].node = true;
        }
        else this.items[i].icon = this.items[i].icongif;
      }
    }
  }

  this.create = function() {
    this.mNr = mObj.length;
    if(mObj[this.mNr] = this) {
      this.buildContainer();
      this.createStructure();
      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, curPos, i;
    var item = 0;
    var level = 1;
    this.curItem = -1;
    if(arguments == null) arguments = this.jumpTo.arguments;
    for(i = 0; i < arguments.length; i++, level++) {
      pos = arguments[i];
      for(curPos = 0; item < this.items.length && curPos < pos; item++) {
        if(this.items[item].level == level) curPos++;
      }
      if(curPos == pos) {
        item -= 1;
        this.openMenu(item);
      }
    }
    if(item) this.jump(item);
  }
  //------------------------------------------------------------------------
}

function makeItem(level, text, url, target, icongif, icongifHilight, onClick, openAll) {
  this.level = level;
  this.text = text;
  this.url = url;
  this.target = target;
  this.icongif = icongif;
  this.icongifHilight = icongifHilight;
  this.onClick = onClick;
  this.icon = '';
  this.node = false;
}

//----------------------------------------------------------------------------------------------------
