function Menus() {
   this.menus = Menus.arguments;
   this.show = menusShow;
   this.hide = menusHide;
   this.setTimer = menusSetTimer;
   this.clearTimer = menusClearTimer;
   this.names = new Array(this.menus.length);
   this.last = -1;
   var i;
   for (i = 0;i < this.menus.length;i++) {
      this.names[this.menus[i].name] = i;
   }
}

function menusShow(name, e, dx, dy) {
   if (this.last >= 0) {
      this.menus[this.last].hide();
   }
   var index = this.names[name];
   var overlay = this.menus[index].overlay;
   if (overlay) {
      var i;
      for (i = 0;i < overlay.length;i++) {
         var obj = document.getElementById(overlay[i]);
         if (obj) {
            obj.style.visibility = 'hidden';
         }
      }
   }
   this.menus[index].show(e, dx, dy);
   this.last = index;
}

function menusHide(name) {
   var index = this.last;
   if (name) {
      index = this.names[name];
   }
   if (index >= 0) {
      this.menus[index].hide();
      var overlay = this.menus[index].overlay;
      if (overlay) {
         var i;
         for (i = 0;i < overlay.length;i++) {
            var obj = document.getElementById(overlay[i]);
            if (obj) {
               obj.style.visibility = 'visible';
            }
         }
      }
   }
   this.last = -1;
}

function menusSetTimer(name) {
   var index = this.names[name];
   if (index >= 0) {
      this.menus[index].setTimer(this.name);
   }
}

function menusClearTimer(name) {
   var index = this.names[name];
   if (index >= 0) {
      this.menus[index].clearTimer();
   }
}

function Menu(name, timer) {
   this.name = name;
   if (!timer) {
      timer = 500;
   }
   this.timer = timer;
   this.show = menuShow;
   this.hide = menuHide;
   this.setTimer = menuSetTimer;
   this.clearTimer = menuClearTimer;
}

function menuShow(e, dx, dy) {
   this.clearTimer();
   var obj = document.getElementById(this.name);
   if (e) {
      var x = 0, y = 0, xMax = 0, yMax = 0;
      x = getXPos(e);
      y = getYPos(e);
      if (document.all) {
         xMax = document.body.clientWidth + document.body.scrollLeft;
         yMax = document.body.clientHeight + document.body.scrollTop;
      }
      else if (document.getElementById) {
         xMax = window.innerWidth + window.pageXOffset;
         yMax = window.innerHeight + window.pageYOffset;
      }
      obj.style.left = (x + dx) + 'px';
      obj.style.top = (y + dy) + 'px';
   }
   obj.style.visibility = 'visible';
}

function menuHide() {
   this.clearTimer();
   var obj = document.getElementById(this.name);
   obj.style.visibility = 'hidden';
}

function menuSetTimer(name) {
   this.timerid = setTimeout(name+".hide('"+this.name+"')", this.timer);
}

function menuClearTimer() {
   if (this.timerid) {
      clearTimeout(this.timerid);
   }
}

var nav = new Menus(
new Menu('about-menu'),
new Menu('services-menu'),
new Menu('portfolio-menu'),
new Menu('news-menu'),
new Menu('careers-menu'));
nav.name = 'nav';

/* Swapping for Services */
function swap(idToShow, totalCount) {
    for (var x = 1; x <= totalCount; x++) {
        var obj = document.getElementById('f' + x);
        obj.style.display = (idToShow == 'f' + x) ? '' : 'none';
    }
}