/*
	xMenu3_1.js
	Cross-Browser.com
*/

var pg = null;
var xDowngrade = true;

if (xInclude('../x_core.js', '../x_event.js', '../x_dom.js', '../x_slide.js', 'xmenu3.js', 'xmenu3_1_dhtml.css'))
{
  xDowngrade = false;
}

window.onload = function() {
  if (!xDowngrade) {
    pg = new xPage();
  }
}

function winOnResize() {
  if (pg) pg.paint();
}
/*************************** COMENTARIO FER VELOCIDAD DE BAJADA DE MENUS...........*/
function winOnScroll() {
  if (pg) {
    var st = xScrollTop();
     m1 /***********eliminar // de la izquierda para parar el movimiento scroll...........*/
    if (st > pg.m1Top) {xSlideTo(pg.m1.ele, xScrollLeft() + pg.m1Left, st, 4000);}
    else {xSlideTo(pg.m1.ele, xScrollLeft() + pg.m1Left, pg.m1Top, 4000);}
     m2 /***********eliminar // de la izquierda para parar el movimiento scroll...........*/
    xSlideTo(pg.m2.ele, xScrollLeft() + pg.m2Left, xScrollTop() + pg.m2Top, 4000);
    xSlideTo(pg.m3.ele, xScrollLeft() + pg.m3Left, xScrollTop() + pg.m3Top, 4000);

  }
}

function xPage() { // object prototype

  /// xPage.paint() Method

  this.paint = function() {
    window.scrollTo(0,0);
    var x, w, cw;
    // Calculate column's width and x coord
    x = this.m2W;
    cw = xClientWidth() - 2 * x;
    if (cw < this.cMinW) {w = this.cMinW;}
    else if (cw > this.cMaxW) {
      w = this.cMaxW; 
      x = (xClientWidth() - w) / 2; // center column in window
    }
    else {w = cw;}
    // Set widths
    xResizeTo(this.h, w, this.hH);              // header
    xWidth(this.c, w);                          // xcolumn   COMENTO PARA NO CAMBIAR TAMAŅO
    xResizeTo(this.f, w, this.fH);              // footer
    //xResizeTo(this.m1.ele, w, this.m1H);        // menu 1    COMENTO PARA NO CAMBIAR TAMAŅO
    //xResizeTo(this.m2.ele, this.m2W, this.m2H); // menu 2
    // set positions
    // header

    xMoveTop(this.h, x, 2);
    xMoveTop(this.m1.ele,xPageY(this.h) + xHeight(this.h)); 
    xMoveTop(this.c, xPageY(this.m1.ele) + xHeight(this.m1.ele)); 
    //xMoveTop(this.m2.ele, (xClientHeight()-xHeight(this.m2.ele)));
    /*AQUI HAY QUE HACER UNA FORMULA PARA VER ESTOOOOOO*/
	var altop;
	altop = xClientHeight();
   	if(altop>=540)
		{
		xMoveTop(this.m2.ele, 0); //altura del menu lateral izquierdo
		xMoveTop(this.m3.ele, 40); //altura del menu lateral derecho
		}
	else
		{
		xMoveTop(this.m2.ele, (xClientHeight()-xHeight(this.m2.ele)-60));
		xMoveTop(this.m3.ele, xClientHeight()-xHeight(this.m3.ele));
		}
	    
    //xMoveTop(this.m3.ele, xClientHeight()-xHeight(this.m3.ele));
    xMoveTop(this.f, xTop(this.c)+xHeight(this.c)); 

//    xMoveTo(this.h, x, 2);
    // posicion menu horizontal
    //xMoveTo(this.m1.ele, x, xPageY(this.h) + xHeight(this.h)); 
    // column
    //xMoveTo(this.c, x, xPageY(this.m1.ele) + xHeight(this.m1.ele)); 
    // posicion menu vertical
 //   xMoveTo(this.m2.ele, x - xWidth(this.m2.ele), xClientHeight()-xHeight(this.m2.ele));
//    xMoveTo(this.m3.ele, x - xWidth(this.m3.ele), xClientHeight()-xHeight(this.m3.ele));
    // footer
    //xMoveTo(this.f, x, xTop(this.c)+xHeight(this.c)); 
    // refresh menu positions
    this.m1.paint();
    this.m2.paint();
    // Show everything
    xShow(this.h);
    xShow(this.c);
    xShow(this.f);
    xShow(this.m1.ele);
    xShow(this.m2.ele);
    // Setup floater offsets
    this.m1Left = xPageX(this.m1.ele) - xScrollLeft();
    this.m1Top = xPageY(this.m1.ele) - xScrollTop();
    //this.m2Left = xPageX(this.m2.ele) - xScrollLeft();
    this.m2Top = xPageY(this.m2.ele) - xScrollTop();
    //this.m3Left = xPageX(this.m3.ele) - xScrollLeft();
    this.m3Top = xPageY(this.m3.ele) - xScrollTop();
    
  }

  /// xPage Properties and Constructor

  // adjustable page parameters
  this.cMinW = 700; // xcolumn min width 300
  this.cMaxW = 700; // xcolumn max width
  this.m2W = 180;    // menu 2 width
  this.m2H = 400;   // menu 2 height
  this.m1H = 65;    // menu 1 height
  this.hH = 50;     // header height
  this.fH = 50;     // footer height

  // element references
  this.h = xGetElementById('xHead');
  this.c = xGetElementById('xColumn');
  this.f = xGetElementById('xFoot');

  // Create menu 1
  this.m1 = new xMenu('xMenu1',         // element id
    'horizontal', 2, -6,                // mnuType, verOfs, hrzOfs
    -12, -16, -20, -4,                  // lbl selection area clipping (top,right,bottom,left)
    -32, null, null, null,              // box selection area clipping
    'myHMBarLbl', 'myHMBarLblHvr',       // barLblOutStyle, barLblOvrStyle
    'myHMBarLblHvrClosed',                // barLblOvrClosedStyle
    'myMLbl', 'myMLblHvr',             // lblOutStyle, lblOvrStyle
    'myHMBar', 'myMBox');            // barStyle, boxStyle

  // Create menu 2
  this.m2 = new xMenu('xMenu2',         // element id
    'vertical', 2, -6,                  // mnuType, verOfs, hrzOfs
    -12, -4, -20, -12,                  // lbl selection area clipping (top,right,bottom,left)
    -32, null, null, null,              // box selection area clipping
    'myVMBarLbl', 'myVMBarLblHvr',       // barLblOutStyle, barLblOvrStyle
    'myVMBarLblHvrClosed',                // barLblOvrClosedStyle
    'myMLbl', 'myMLblHvr',             // lblOutStyle, lblOvrStyle
    'myVMBar', 'myMBox');            // barStyle, boxStyle


  // Create menu 3
  this.m3 = new xMenu('xMenu3',         // element id
    'vertical', 2, -6,                  // mnuType, verOfs, hrzOfs
    -12, -4, -20, -12,                  // lbl selection area clipping (top,right,bottom,left)
    -32, null, null, null,              // box selection area clipping
    'myVMBarLbl', 'myVMBarLblHvr',       // barLblOutStyle, barLblOvrStyle
    'myVMBarLblHvrClosed',                // barLblOvrClosedStyle
    'myMLbl', 'myMLblHvr',             // lblOutStyle, lblOvrStyle
    'myVMBar', 'myMBox');            // barStyle, boxStyle
  
  //
  this.m1.load();
  this.m2.load();
  this.m3.load();
  // Paint everything
  this.paint();
  
  // Set menu z's
  xZIndex(this.m1.ele, 20); //z-index
  xZIndex(this.m2.ele, 30);
  xZIndex(this.m3.ele, 10);  
  // Listen to resize and scroll events
  xAddEventListener(window, 'resize', winOnResize);
  xAddEventListener(window, 'scroll', winOnScroll);
}


