/* Version: CVS $Id$ */

var cbeMenu, navDiv, downgrade = true, ua = navigator.userAgent.toLowerCase();

if (ua.indexOf('msie') != -1 && parseInt(navigator.appVersion) >= 4		// IE4 up
  || ua.indexOf('gecko') != -1																											// Gecko
  || ua.indexOf('konqueror') != -1																								// Konquerer
  || window.opera																																		// Opera
) { downgrade = false; }

function windowOnload() {
  cbeMenu = newCBEMenu();
  window.cbe.addEventListener('resize', winResizeListener, false);
  cbeAfterOnload();
}

function winResizeListener() {
  //cbeMenu.paint(navDiv.pageX(), navDiv.pageY());
}

// begin class cbeDropdownMenu

function cbeDropdownMenu(mnuX, mnuY, lblW, lblH, lblPad, boxW, itmLRpad, itmH, subItmSpace, bgColor, boxBgColor, txtColor, hvrBColor, hvrTColor) {

  // Properties
  this.mnuX = mnuX;
  this.mnuY = mnuY;
  this.lblW = lblW;
  this.lblPad = lblPad;
  this.lblH = lblH;
  this.boxW = boxW;
  this.itmLRpad = itmLRpad;
  this.itmH = itmH;
  this.subItmSpace = subItmSpace;
  this.bgColor = bgColor;
  this.boxBgColor = boxBgColor;
  this.txtColor = txtColor; 
  this.hvrBColor = hvrBColor;
  this.hvrTColor = hvrTColor;
  this.lblCount = 0;
  this.lblActive = null;
  
  // Methods
  this.paint = function(mnuX, mnuY) { // this is the only public method
    if (arguments.length > 0) this.mnuX = mnuX;
    if (arguments.length > 1) this.mnuY = mnuY;
    var lbl = null; // of type Element
    var box = null; // of type CBE
    var mX = this.mnuX;

    this.lblCount = 0;
    do {
      ++this.lblCount;
      lbl = cbeGetElementById(CBE_LEVEL1_ID_PREFIX + this.lblCount)
      if (lbl) {
        // HOOK: params: 1) object: cbeMenu, 2) object: L1 div
        cbeL1PaintHook(this, lbl.cbe);
        if (lbl.cbe.nextSibling && lbl.cbe.nextSibling.id.indexOf(CBE_LEVEL1_ID_PREFIX)==-1) box = lbl.cbe.nextSibling;
        else box = null;
        lbl.cbe.childBox = box;
        lbl.cbe.parentLabel = null;
        if (box) this.paintBox(box, lbl.cbe, mX, this.mnuY + lbl.cbe.height(), this.lblCount);
        mX += lbl.cbe.width() + lblPad;
      }
    } while(lbl);
    --this.lblCount;
  }

  this.paintBox = function(box, parent, x, y, lblCount) {
    // HOOK: params: 1) object: cbeMenu, 2) object: cbe box, 3) object: cbe parent, 4) int: x, 5) int: y, 6) int: #labels
    cbePaintBoxHook(this, box, parent, x, y, lblCount);
  }

  this.mousemoveListener = function(e) {
    // HOOK: params: 1) object: cbeMenu, 2) object: cbe-event
    cbeMousemoveHook(this, e);
  }

  this.mouseclickListener = function(e) {
    // HOOK: params: 1) object: cbeMenu, 2) object: cbe-event
    cbeMouseclickHook(this, e);
    var isL1 = e.cbeTarget.id.indexOf(CBE_LEVEL1_ID_PREFIX)==0;
    var hasChildren = e.cbeTarget.childBox;
    if (isL1) {
      // HOOK: params: 1) object: cbeMenu, 2) object: event target
      cbeL1ClickHook(this, e.cbeTarget);
    } else if (hasChildren) {
      // HOOK: params: 1) object: cbeMenu, 2) object: event target
      cbeLSubClickHook(this, e.cbeTarget);
    }
    //else: box is not L1 and has no children => follow link
  }
  
  // Constructor Code
  this.paint();
  if (CBE_LISTEN_TO_MOUSEMOVE) {
    document.cbe.addEventListener('mousemove', this.mousemoveListener, false, this);
  }
  if (CBE_LISTEN_TO_CLICK) {
    document.cbe.addEventListener('click', this.mouseclickListener, false, this);
  }
} // end class cbeDropdownMenu
