function paintMenus(){
  var styleCorrection=(ua.indexOf('msie') != -1 && ua.indexOf('mac') != -1)?2:0;
  var expand=(cbeInnerWidth()<850)?false:true;
  //set up the logo layer
  logoObj=cbeGetElementById('scanlogo').cbe;
  var logo_x=expand?700:500;
  logoObj.moveTo(logo_x,1);
  logoObj.width(cbeInnerWidth()-logo_x);
  logoObj.height(50);
  logoObj.show();
  //set up the search layer
  siObj=cbeGetElementById('searchInput').cbe;
  searchInputX=expand?550:350;
  searchInputX+=(styleCorrection/2);
  siObj.moveTo(searchInputX,0);
  siObj.height(50-styleCorrection);
  siObj.width(100-styleCorrection);
  siObj.show();
  mnuMarker = cbeGetElementById('mnuMarker').cbe;
  var spacing=expand?50:0;
  var textColours=['#ffffff','#000000','#000000','#000000'];
  var bgColours=["#ff0000","#c6c6c6","#a2a2a2","#e9e9e9"];
  var hvrBgColours=["#ff0000","#ffff00","#9c30ad","#00ffff"];
  var hvrTxtColours=['#ffffff','#000000','#ffffff','#000000'];
  var lblWidth=100-styleCorrection;
  var lblHeight=50-styleCorrection;
  var itmHeight=25;//-(styleCorrection/2);
  if (!downgrade) cbeMenu = new cbeDropdownMenu(
    0, 0,                                 // coord of first label
    lblWidth, lblHeight,                  // label width and height
    lblWidth,                             // box width
    itmHeight,                            // item height
    0,                                    // item left padding
    spacing,                              // menu spacing
    bgColours,                            // background color
    textColours,                          // text color
    hvrBgColours,                         // hover background color
    hvrTxtColours,                        // hover text color
    styleCorrection                       // correction for border display in IE/Mac
  );
  window.cbe.addEventListener('resize', winResizeListener, false);
  cbeGetElementById('l0').cbe.addEventListener('click', homeButtonLink, false);
}
// CBE Cascading Drop-down Menu
// copyright (c) 2002 Mike Foster
// get CBE at cross-browser.com
// CBE and cbeDropdownMenu are licensed under the LGPL

// v1.5 30Oct02 - bug fix for when label with no box is the last label
// v1.4 29Oct02 - added support for main labels with no boxes
// v1.3 01Oct02 - utilizes the update to CBE v4.15 which allows object methods to be used as event listeners
// v1.2 27Aug02 - now licensed under LGPL
// v1.1 20Aug02 - added optional parameters to the paint() method, for re-painting on win resize
// v1.0 17Aug02 - initial release

var
  cbeMenu,
  mnuMarker,
  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
) {
  document.write("<link rel='stylesheet' type='text/css' href='/css/menus2.css' media='screen'>");
  downgrade = false;
} else {
  document.write("<link rel='stylesheet' type='text/css' href='/css/nomenus.css'>");
}

function homeButtonLink(){
  location.replace('/scan.php');
}

function winResizeListener() {
  location.reload();
}

// begin class cbeDropdownMenu

function cbeDropdownMenu(mnuX, mnuY, lblW, lblH, boxW, itmH, itmPad, itmSpacing, bgColor, txtColor, hvrBColor, hvrTColor, styleCorrection) {

  // Properties

  this.mnuX = mnuX;
  this.mnuY = mnuY;
  this.lblW = lblW;
  this.lblH = lblH;
  this.boxW = boxW;
  this.itmH = itmH;
  this.itmPad = itmPad;
  this.bgColor = bgColor;  
  this.txtColor = txtColor; 
  this.hvrBColor = hvrBColor;
  this.hvrTColor = hvrTColor;
  this.lblCount = 0;
  this.lblActive = null;
  this.itmSpacing = itmSpacing;
  this.goLeft=false;
  this.ie_fix=styleCorrection;
  
  // 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 = -1;
    do {
      ++this.lblCount;
      lbl = cbeGetElementById('l' + this.lblCount)
      if (lbl) {
        with (lbl.cbe) {
          color(this.txtColor[this.lblCount]);    
          background(this.bgColor[this.lblCount]);
          zIndex(2002);
          var labelW=(this.lblCount==0)?(this.lblW/2):this.lblW;
          resizeTo(labelW, this.lblH);
          moveTo(mX, this.mnuY);
          show();
        }
        if (lbl.cbe.nextSibling && lbl.cbe.nextSibling.id.indexOf('l')==-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()+this.itmSpacing;
      }
    } while(lbl);
    --this.lblCount;
  }

  this.paintBox = function(box, parent, x, y, idx) {
    var mx=0, my=0, itmCount=0, nextx=0;
    box.background(this.bgColor[idx]);
    box.width(this.boxW);
    box.moveTo(x, y);
    box.zIndex(2002);
    var itm = box.firstChild;
    while (itm) {
      if (itm.id.indexOf('i') != -1) {
        itm.color(this.txtColor[idx]);
        itm.background(this.bgColor[idx]);
        itmHeight=(itm.height()>this.itmH)?(itm.height()+(this.itmH-(itm.height()%this.itmH))):this.itmH;
        //alert(itm.height());
        //alert(itmHeight-this.ie_fix);
        itm.resizeTo(this.boxW, itmHeight-this.ie_fix);
        itm.moveTo(mx + this.itmPad, my);
        itm.show();
        my += itmHeight;
        ++itmCount;
      }
      else {
        itm.previousSibling.childBox = itm;
        itm.previousSibling.parentLabel = parent;
        if((itm.pageX()+200)>cbeInnerWidth()||(this.goLeft&&(itm.pageX()-100)>0)){
          this.goLeft=true;
          nextx=(mx-100);
        }else{
          this.goLeft=false;
          nextx=(mx+100);
        }
        this.paintBox(itm, itm.previousSibling, nextx, my - itm.previousSibling.height(), idx);
      }
      itm = itm.nextSibling;
    }
    box.height(itmCount * this.itmH);
  }

  this.mousemoveListener = function(e) {
    if (
      this.lblActive &&
      (e.cbeTarget != this.lblActive.childBox &&
      e.cbeTarget != this.lblActive &&
      e.cbeTarget.parentNode != this.lblActive.childBox)
    ) {
      if (this.lblActive.childBox) this.lblActive.childBox.hide();
      idx=this.lblActive.id.charAt(1).valueOf();
      this.lblActive.color(this.txtColor[idx]);
      this.lblActive.background(this.bgColor[idx]);
      this.lblActive = this.lblActive.parentLabel;
    }
    else if (e.cbeTarget.childBox || e.cbeTarget.id.indexOf('l')==0) {
      idx=e.cbeTarget.id.charAt(1).valueOf();
      e.cbeTarget.color(this.hvrTColor[idx]);
      e.cbeTarget.background(this.hvrBColor[idx]);
      this.lblActive = e.cbeTarget;
      if (this.lblActive.childBox) this.lblActive.childBox.show();
    }
    if(window.move) window.move(e);
  }
  
  // Constructor Code

  this.paint();
  document.cbe.addEventListener('mousemove', this.mousemoveListener, false, this);

} // end class cbeDropdownMenu

