var a=0; var b=0; var d=0;
var c=0;
var am=null;

// pseudo base class

   function addMenuObjectBase (menuobject) {
      this.menuObjects.push(menuobject);
   }

   function getObjectMenu (id) {
      var theObject = null;
      if ( this.id == id ) {
         theObject = this;
      } else {
         for ( var i=0; i<this.menuObjects.length; i++ ) {
            if ( this.menuObjects[i].id == id ) {
               theObject = this.menuObjects[i];
               break;
            }
         }
      }
      return theObject;
   }
   function getObjectBase ( id ) {      var theObject = null;      if ( this.id == id ) {
         theObject = this;
      } else {
         for ( var i=0; i<this.menuObjects.length; i++ ) {
            theObject = this.menuObjects[i].getObject(id);
            if ( theObject != null ) break; // found the object
         }
      }
      return theObject;
   }


   function getInfoBase(level) {
      var str = '<br> Length = ' + this.menuObjects.length;
      for ( var i=0; i<this.menuObjects.length; i++ ) {
         str = str + '<br> Level ' + level + '  id = ' + this.menuObjects[i].id;
         str = str + this.menuObjects[i].getInfo(level+1);
      }
      return str;
   }

// navbar class
   function NavBar () {
      this.className = 'NavBar';      this.menuObjects = new Array();      this.selectedid = null;//      this.topofnavbar = topofnavbar;      this.id =0;      //display attributes      this.spacingx = 0;      this.spacingy = 20;      // functions      this.addMenuObject = addMenuObjectBase;//      this.getIndex = getIndexNavBar;        this.getObject = getObjectBase;        this.getWidth = getWidthNavBar;//      this.selectObject = selectObjectNavBar;//      this.setDisplay = setDisplayNavBar;//      this.setExpanded = setExpandedNavBar;      this.setHoverEffects = setHoverEffectsNavBar;      this.show = showNavBar;      this.getInfo = getInfoBase;   }
   function setHoverEffectsNavBar(element,event) {
      var menuObject = this.getObject(element.id);
      var atag = document.getElementById( 'atag' + element.id );
      switch(event.type) {
         case 'mouseover':
            element.style.color = menuObject.colorHover;
            element.style.backgroundColor = menuObject.backgroundColorHover;
            atag.style.color = menuObject.colorHover;
            atag.style.backgroundColor = menuObject.backgroundColorHover;
            break;
         case 'mouseout':
            element.style.color = menuObject.color;
            element.style.backgroundColor = menuObject.backgroundColor;
            atag.style.color = menuObject.color;
            atag.style.backgroundColor = menuObject.backgroundColor;
            break;
      }
   }

   function getWidthNavBar (wrapLength) {
      var width = 0;
      for ( var i=0; i<this.menuObjects.length; i++ ) {
         if ( width < wrapLength ) {
            width = width + this.menuObjects[i].width + this.spacingx;
         } else {
            break;
         }
      }
      return width - this.spacingx;
   }

   function showNavBar(x,y,dx,dy) {
   return;
      var xo,yo, nthwrap, widthNB;
      var wrapLength = 800;  // magic number
      widthNB = this.getWidth(wrapLength);
//      xo = parseInt(( self.screen.availWidth - 22 - widthNB ) / 2);
// window.document.body.clientWidth
//      xo = parseInt( (window.document.body.clientWidth -20 - widthNB ) / 2 );
      xo = 0;
      yo = y;
      nthwrap = 1;
      x = xo;
      for ( var i=0; i<this.menuObjects.length; i++ ) {
         this.menuObjects[i].element = document.getElementById(this.menuObjects[i].id);
         this.menuObjects[i].element.style.visibility = 'visible';
//         if ( this.menuObjects[i].parentid != 0 ) {
//         this.menuObjects[i].element.style.left = x + "px";
//         this.menuObjects[i].element.style.top = y + "px";
//         this.menuObjects[i].element.style.position = 'relative';
//         }
//         this.menuObjects[i].element.style.width  = this.menuObjects[i].width + "px";
         this.menuObjects[i].element.style.color = this.menuObjects[i].color;
         this.menuObjects[i].element.style.backgroundColor = this.menuObjects[i].backgroundColor;
         var atag = document.getElementById('atag'+this.menuObjects[i].id);
         atag.style.color = this.menuObjects[i].color;
         atag.style.backgroundColor = this.menuObjects[i].backgroundColor;

/*
//         if ( x > wrapLength ) {
         if ( i == 9 ) {
            x = xo;
            y = yo + nthwrap * 30;
            nthwrap++;
         } else {
            x = x + this.menuObjects[i].width + this.spacingx;
            y = y + dy;
         }
*/
      }
   }



// MenuObject Class

   function MenuObject (id, parentid) {
      this.className = 'MenuObject';      this.id = id; // id      this.parentid = parentid; // id      // default position and increment for submenu      this.xstart = 20;      this.ystart = 20;      this.dx = 0;      this.dy = 20;      this.element = null;  // set in show      // display attributes      this.isEnabled = 0; // 1 =true; 0=false      this.isExpanded = 0; // 1 =true; 0=false for child MenuObjects      this.color = '#eeeeef';      this.colorHover = '#feeeef';      this.colorClick = '#feeeef';      this.backgroundColor = '#eeeeef';      this.backgroundColorHover = '#feeeef';      this.backgroundColorClick = '#feeeef';      this.backgroundColorEnabled = '#ffffff';      this.backgroundColorDisabled = '#ffffff';//      this.height = height;//      this.width = width;      this.spacingx = 20;      this.spacingy = 20;//      this.backgroundColor = (this.isEnabled) ? this.backgroundColorEnabled : this.backgroundColorDisabled;//      this.objectDiv = document.getElementById(id+'a'); // handle to the  div//      this.objectDiv.style.display = 'none';      this.menuObjects = new Array(); // holds menuobject handles      // Functions      this.addMenuObject = addMenuObjectBase; // add a MenuObject to the array      this.getObject = getObjectBase;      this.hide = hideMenu; // hides the menu      this.hideSiblings = hideSiblingsMenu; // hides the menu      this.setColors = setColorsMenu;      this.show = showMenu; // shows the Menu//      this.selectObject = selectObjectMenuBase;//      this.getBackgroundColor = getBackgroundColorBase;//      this.setDisplay = setDisplayMenu; // changes the display none-block etc//      this.setExpanded = setExpandedMenu; // changes the isExpanded value      this.getInfo = getInfoBase;      this.findRootid = findRootidMenu;   }   function setColorsMenu ( c, ch, cc, bc, bch, bcc ) {      this.color = c;      this.colorHover = ch;      this.colorClick = cc;      this.backgroundColor = bc;      this.backgroundColorHover = bch;      this.backgroundColorClick = bcc;   }function findPos(obj,d,h){//gets the absolute position of the objectsvar x = obj.offsetLeft;var y = obj.offsetTop;
//alert ("x,y = " + x +',' + y);

while(obj.offsetParent){
if(obj==document.getElementsByTagName('body')[0]){break;}
else{
x=x+obj.offsetParent.offsetLeft;
y=y+obj.offsetParent.offsetTop;
obj=obj.offsetParent;
}
}
d=x;h=y;
}
   function showMenu (event) {      var xx = this.xstart;      var yy = this.ystart;//alert ( " xx, yy ) + " + xx + ',' + yy);      this.element = document.getElementById(this.id);      var de,he;//findPos(this.element,de,he);//alert ("d,h = " + de +',' + he);var posx = 0;	var posy = 0;
	if (!e) var e = event;
	if (e.pageX || e.pageY)
	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		posx = e.clientX + document.body.scrollLeft;
		posy = e.clientY + document.body.scrollTop;
	}    xx=posx;    yy = posy;/*   alert ( "event(x,y)=" + posx +',' + posy + " (x,y)=" + this.element.offsetTop +',' + this.element.offsetLeft +" (w,h)=" + this.element.offsetWidth +',' + this.element.offsetHeight);*/      this.element.style.color = this.colorClick;      this.element.style.backgroundColor = this.backgroundColorClick;      var atag = document.getElementById('atag'+this.id)      atag.style.color = this.colorClick;      atag.style.backgroundColor = this.backgroundColorClick;      if ( !this.isExpanded ) {         if ( am != null ) {            // test for parent            if ( am.id == this.parentid ) {                // child menu, so do not hide am                // hide siblings if open                am.hideSiblings(this.id);            } else {               if (this.findRootid() != am.id ) {                  am.hide();
               }
            }
         }
         for ( var i=0; i<this.menuObjects.length; i++ ) {            this.menuObjects[i].element = document.getElementById(this.menuObjects[i].id);//alert ( "sub (x,y)=" + this.menuObjects[i].element.style.left +',' + this.menuObjects[i].element.style.top);/////            this.menuObjects[i].element.style.left = xx + "px";/////            this.menuObjects[i].element.style.top  = yy + "px";
            this.menuObjects[i].element.style.visibility = 'visible';
//            this.menuObjects[i].element.style.position = 'relative';
////            this.menuObjects[i].element.style.width  = this.menuObjects[i].width+ "px";;
            atag = document.getElementById('atag'+this.menuObjects[i].id)
            atag.style.color = this.menuObjects[i].color;            atag.style.backgroundColor = this.menuObjects[i].backgroundColor;////            xx = xx + this.dx;
////            yy = yy + this.dy;
         }
         d = 1;
         this.isExpanded = true;

      }
   }   function findRootidMenu() {      var rootid = 'qqq';      if ( this.parentid.length > 0 ) {         var obj = navbar.getObject(this.parentid);         rootid = obj.findRootid();      } else {         rootid = this.id;      }      return rootid;   }   function hideMenu () {      this.element = document.getElementById(this.id);      this.element.style.color = this.color;      this.element.style.backgroundColor = this.backgroundColor;      var atag = document.getElementById('atag'+this.id);      atag.style.color = this.color;      atag.style.backgroundColor = this.backgroundColor;      for ( var i=0; i<this.menuObjects.length; i++ ) {         this.menuObjects[i].element = document.getElementById(this.menuObjects[i].id);         this.menuObjects[i].element.style.visibility = 'hidden';         if ( this.menuObjects[i].isExpanded ) {            this.menuObjects[i].hide();         }         this.isExpanded = false;      }   }
   function hideSiblingsMenu (sibid) {
      if ( this.id != sibid ) {         for ( var i=0; i<this.menuObjects.length; i++ ) {            if ( sibid != this.menuObjects[i].id ) {               if ( this.menuObjects[i].isExpanded ) {                  this.menuObjects[i].hide();               }            }         }      }   }

   function bodyClick() {
  // alert(d);
      if ( d!=1) {
         if ( am != null ) {
      //   alert(am);
         am.hide();
         am = null;
         }
      }
      d=0;

   }




//   function MenuObject (id, isEnabled, classname, parentid, menuid)
   var navbar = new NavBar();


   function setActiveMenu(element,event) {
      var menu = navbar.getObject(element.id);
      menu.show(event);
      am = menu;
   }

   function setHover(element,event) {
      var menu = navbar.getObject(element.id);
      if ( !menu.isExpanded ) {
         navbar.setHoverEffects(element,event);
      }
   }


//alert(self.screen.availWidth);
