/* the script for this menu is largely written by XX, used under the GPL licence */

var mark1, menu1, menu2;
function windowOnload() {
  mark1 = cbeGetElementById('menuMarker1').cbe;
  menu1 = new cbeMenu(
    true,                       // horizontal,
    (document.cbe.width()-(3*75))/2, mark1.pageY(), 3, // centered
//    mark1.pageX(), mark1.pageY(), 3, // menuX, menuY, menuZ (left-justified)
    [0,0,0], 0, 0,          // lblWidthsArray, lblHeight, lblspacing
    [0,0,0],              	// boxWidthsArray,
    '#ffffff', '#ffffff',       // activeColor, inactiveColor,
    '#ffffff', '#ffffff',       // activeBkgnd, inactiveBkgnd
    '#ffffff'                   // boxBkgnd
  );
  menu2 = new cbeMenu(
    false,                      // horizontal,
    15, 160, 2,			// menuX, menuY, menuZ
    [190,190,190,190,190,190], 25, 8,       // box widths array, box height, spacing between boxes
    [0,0,240,230,0,0],          // opened menu WidthsArray,
    '#000000', '#ffffff',       // active text Color, inactive text Color,
    '#8298a6', '#012e4a',       // active box Bkgnd, inactive box Bkgnd
    '#012e4a'                   // boxBkgnd
  );

  window.cbe.addEventListener("resize", resizeListener, false);
}

function resizeListener(e) {
  if (is.opera5or6 || is.nav4) {
    location.replace(location.href);
  }
  else {
    
    menu2.paint(0, 250);
    
  }
}

////

var cbeTotalMenus=0, cbeActiveMenu=null;
function cbeMenu(
  horizontal,
  menuX, menuY, menuZ,
  lblWidthsArray, lblHeight, lblSpacing,
  boxWidthsArray,
  activeColor, inactiveColor,
  activeBkgnd, inactiveBkgnd,
  boxBkgnd
) {
  // properties
  this.n = ++cbeTotalMenus;
  this.hz = horizontal;
  this.x = menuX;
  this.y = menuY;
  this.z = menuZ;
  this.lblW = lblWidthsArray;
  this.lblH = lblHeight;
  this.lblSpc = lblSpacing;
  this.boxW = boxWidthsArray;
  this.ac = activeColor;
  this.ic = inactiveColor;
  this.ab = activeBkgnd;
  this.ib = inactiveBkgnd;
  this.bb = boxBkgnd;
  this.active = null;
  // methods
  this.paint = function(menuX, menuY) {
    var i=1, x, y, lbl, box;
    if (arguments.length > 1) {
      this.x = menuX;
      this.y = menuY;
    }
    x = this.x;
    y = this.y;
    lbl = cbeGetElementById('label'+this.n+""+i);
    while (lbl) {
      lbl = lbl.cbe;
      lbl.zIndex(this.z);
      lbl.resizeTo(this.lblW[i-1], this.lblH);
      lbl.moveTo(x, y);
      lbl.color(this.ic);
      lbl.background(this.ib);
      lbl.show();
      lbl.box = i;
      lbl.menu = this;
      if (arguments.length==3) lbl.addEventListener('mouseover', menuShowListener, false);
      lbl.box = cbeGetElementById('box'+this.n+""+i).cbe;
      if (lbl.box) {
        lbl.box.width(this.boxW[i-1]);
        var bx, by;
        if (this.hz) { // horizontal
          if (x + this.boxW[i-1] > window.cbe.width()) { bx = x - (this.boxW[i-1] - this.lblW[i-1]); }
          else { bx = x; }
          if (y + this.lblH + lbl.box.height() > window.cbe.height()) { by = y - lbl.box.height(); }
          else { by = y + this.lblH; }
        }
        else { // vertical
          if (x + this.boxW[i-1] > window.cbe.width()) { bx = x - this.boxW[i-1]; }
          else { bx = x + this.lblW[i-1]; }
          if (y + lbl.box.height() > window.cbe.height()) { by = y + this.lblH - lbl.box.height(); }
          else { by = y; }
        }
        lbl.box.moveTo(bx, by);
        lbl.box.lbl = lbl;
        lbl.box.zIndex(this.z);
        lbl.box.background(this.bb);
        lbl.box.hide();
      }
      if (this.hz) x += this.lblW[i-1] + this.lblSpc;
      else y += this.lblH + this.lblSpc;
      lbl = cbeGetElementById('label'+this.n+""+(++i));
    }
  }
  // constructor code
  this.paint(this.x, this.y, 'init');
  document.cbe.addEventListener("mousemove", menuHideListener, false);
}
function menuShowListener(e) {
  var lbl = e.cbeCurrentTarget;
  var menu = lbl.menu;
  if (menu.active) {
    if (menu.active == lbl) return;
    menu.active.box.hide();
    menu.active.color(menu.ic);
    menu.active.background(menu.ib);
  }
  if (cbeActiveMenu && cbeActiveMenu != menu) {
    menuHide(cbeActiveMenu);
  }
  lbl.box.show();
  lbl.color(menu.ac);
  lbl.background(menu.ab);
  menu.active = lbl;
  cbeActiveMenu = menu;
}
function menuHideListener(e) {
  if (cbeActiveMenu && cbeActiveMenu.active && !e.cbeTarget.lbl && !e.cbeTarget.box) {
    menuHide(cbeActiveMenu);
  }
}
function menuHide(menu) {
  menu.active.box.hide();
  menu.active.color(menu.ic);
  menu.active.background(menu.ib);
  menu.active = null;
  cbeActiveMenu = null;
}

//            alert(//////////
//              "x: " + x
//              +"\nboxW:" + this.boxW[i-1]
//              +"\nx + boxW:" + (x + this.lblW[i-1])
//              +"\nwindow width: " + window.cbe.width()
//              +"\n"+ (this.boxW[i-1] - this.lblW[i-1])
//            );//////////

//--></script>
