
var mark1, menu1, menu2, menu3, menu4;

function windowOnload() {
  mark1 = cbeGetElementById('menuMarker1').cbe;
  menu1 = new cbeMenu(
    true,                       // horizontal,
   //(document.cbe.width()-(4*205))/2 , mark1.pageY(), 1, // centered
    mark1.pageX()+3, mark1.pageY(), 3, // menuX, menuY, menuZ (left-justified)
    [212,27,0], 27, 5,          // lblWidthsArray, lblHeight, lblspacing
    [212,17,1],              // boxWidthsArray,
    '#3C5C73', '#3C5C73',       // activeColor, inactiveColor,
    '#E8ECDD', '#E8ECDD',       // activeBkgnd, inactiveBkgnd
    '#E8ECDD'                   // boxBkgnd
  );
  
  menu2 = new cbeMenu(
    true,                       // horizontal,
    //(document.cbe.width()-(5*153))/2 + 154, mark1.pageY(), 2, // centered
    mark1.pageX()+213, mark1.pageY(), 3, // menuX, menuY, menuZ (left-justified)
    [212,27,1], 27, 30,          // lblWidthsArray, lblHeight, lblspacing
    [205,17,1],              // boxWidthsArray,
    '#3C5C73', '#3C5C73',       // activeColor, inactiveColor,
    '#E8ECDD', '#E8ECDD',       // activeBkgnd, inactiveBkgnd
    '#E8ECDD'                   // boxBkgnd
  );  
  menu3 = new cbeMenu(
    true,                       // horizontal,
    //(document.cbe.width()-(5*155))/2 + 311, mark1.pageY(), 3, // centered
    mark1.pageX()+418, mark1.pageY(), 3, // menuX, menuY, menuZ (left-justified)
    [205,17,1], 27, 30,          // lblWidthsArray, lblHeight, lblspacing
    [226,17,1],              // boxWidthsArray,
    '#3C5C73', '#3C5C73',       // activeColor, inactiveColor,
    '#E8ECDD', '#E8ECDD',       // activeBkgnd, inactiveBkgnd
    '#E8ECDD'                   // boxBkgnd
  );
  menu4 = new cbeMenu(
    true,                       // horizontal,
    //(document.cbe.width()-(5*155))/2 + 311, mark1.pageY(), 3, // centered
    mark1.pageX()+640, mark1.pageY(), 3, // menuX, menuY, menuZ (left-justified)
    [205,17,1], 27, 30,          // lblWidthsArray, lblHeight, lblspacing
    [215,17,1],              // boxWidthsArray,
    '#3C5C73', '#3C5C73',       // activeColor, inactiveColor,
    '#E8ECDD', '#E8ECDD',       // activeBkgnd, inactiveBkgnd
    '#E8ECDD'                   // boxBkgnd
  );  
  
 
  window.cbe.addEventListener("resize", resizeListener, false);
}

function resizeListener(e) {
  

//  if (is.opera5or6 || is.nav4) {
//    location.replace(location.href);
//  }
//  else {
//    mark1 = cbeGetElementById('menuMarker1').cbe;  
//    menu1.paint((document.cbe.width()-(5*153))/2 + 7, mark1.pageY());
//    menu2.paint((document.cbe.width()-(5*153))/2 + 161, mark1.pageY());
//    menu3.paint((document.cbe.width()-(5*155))/2 + 318, mark1.pageY());
//	menu4.paint((document.cbe.width()-(5*155))/2 + 487, mark1.pageY());
//	menu5.paint((document.cbe.width()-(5*155))/2 + 630, mark1.pageY());
//  }
location.replace(location.href);
}

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-3, by);
        lbl.box.lbl = lbl;
        lbl.box.zIndex(this.z);
		//lbl.box.zIndez(3);
        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);
  //document.cbe.addEventListener("click", 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;
}

var idTimeOut;

function menuHideListener(e) {
  if (cbeActiveMenu && cbeActiveMenu.active && !e.cbeTarget.lbl && !e.cbeTarget.box) {
//  var miMenu = cbeActiveMenu;
  	//for (pruebaI=0; pruebaI<200000;pruebaI += 1){
  
//  }	
    //idTimeOut = window.setTimeOut(alert('Hola'),500);
	menuHide(cbeActiveMenu);
  }
}
function menuHide(menu) {
//  window.clearTimeOut(idTimeOut);
  menu.active.box.hide();
  menu.active.color(menu.ic);
  menu.active.background(menu.ib);
  menu.active = null;
  cbeActiveMenu = null;
}
