nav = new Menus(
new Menu('company-menu'),
new Menu('buildonyourlot-menu'));
nav.name = 'nav';

function Menus() {
   this.menus = Menus.arguments;
   this.show = menusShow;
   this.hide = menusHide;
   this.toggle = menusToggle;
   this.visible = menusVisible;
   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 menusVisible(name) {
   var index = this.names[name];
   return(this.menus[index].visible());
}

function menusToggle(name) {
   var visible = this.visible(name);
   if (visible) {
      this.hide(name);
   }
   else {
      this.show(name);
   }
}

function menusShow(name, e, dx, dy, rx, ry) {
   if (this.overlay) {
      var i;
      for (i = 0;i < this.overlay.length;i++) {
         var obj = document.getElementById(this.overlay[i]);
         if (obj) {
            obj.style.visibility = 'hidden';
         }
      }
   }
   if (this.last >= 0) {
      this.menus[this.last].hide();
   }
   var index = this.names[name];
   this.menus[index].show(e, dx, dy, rx, ry);
   this.last = index;
}

function menusHide(name) {
   var index = this.last;
   if (name) {
      index = this.names[name];
   }
   if (index >= 0) {
      this.menus[index].hide();
   }
   this.last = -1;
   if (this.overlay) {
      var i;
      for (i = 0;i < this.overlay.length;i++) {
         var obj = document.getElementById(this.overlay[i]);
         if (obj) {
            obj.style.visibility = 'visible';
         }
      }
   }
}

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, type, timer) {
   this.name = name;
   if (!type) {
      type = 'visibility';
   }
   if (!timer) {
      timer = 200;
   }
   this.type = type;
   this.timer = timer;
   this.show = menuShow;
   this.hide = menuHide;
   this.visible = menuVisible;
   this.setTimer = menuSetTimer;
   this.clearTimer = menuClearTimer;
}

function menuVisible() {
   var obj = document.getElementById(this.name);
   if (this.type == 'visibility') {
      if (obj.style.visibility == 'visible') {
         return(true);
      }
      else {
         return(false);
      }
   }
   else {
      if (obj.style.display == this.type) {
         return(true);
      }
      else {
         return(false);
      }
   }
}

function menuShow(e, dx, dy, rx, ry) {
   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;
         //dx += rx;
         //dy += ry;
      }
      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';
   }
   if (this.type == 'visibility') {
      obj.style.visibility = 'visible';
   }
   else {
      obj.style.display = this.type;
   }
}

function menuHide() {
   this.clearTimer();
   var obj = document.getElementById(this.name);
   if (this.type == 'visibility') {
      obj.style.visibility = 'hidden';
   }
   else {
      obj.style.display = 'none';
   }
}

function menuSetTimer(name) {
   this.timerid = setTimeout(name+".hide('"+this.name+"')", this.timer);
}

function menuClearTimer() {
   if (this.timerid) {
      clearTimeout(this.timerid);
   }
}

// Scroll Code

function dynObj(id,x,y,w,h) {
	this.el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? getLyrRef(id,document): null;
	if (!this.el) return null;
	this.doc = (document.layers)? this.el.document: this.el;
	this.css = (this.el.style)? this.el.style: this.el;
	var px = (document.layers||window.opera)? "": "px";
	this.x = x || 0;	if (x) this.css.left = this.x+px;
	this.y = y || 0;	if (y) this.css.top = this.y+px;
	this.width = w? w: (this.el.offsetWidth)? this.el.offsetWidth: (this.css.clip.width)? this.css.clip.width: 0;
	this.height = h? h: (this.el.offsetHeight)? this.el.offsetHeight: (this.css.clip.height)? this.css.clip.height: 0;
	// if w/h passed, set style width/height
	if (w){ (document.layers)? this.css.clip.width=w+px: this.css.width=w+px;}
	if (h){ (document.layers)? this.css.clip.height=h+px: this.css.height=h+px;}
	this.obj = id + "dynObj"; 	eval(this.obj + "=this");
}

function dw_show() { this.css.visibility = "visible"; }
function dw_hide() { this.css.visibility = "hidden"; }

function dw_shiftTo(x,y) {
	if (x!=null) this.x=x; if (y!=null) this.y=y;	
	// rounded below (this.x/y can hold decimals)
	if (this.css.moveTo) { 
		this.css.moveTo(Math.round(this.x),Math.round(this.y)); 
	} else { 
		this.css.left=Math.round(this.x)+"px"; 
		this.css.top=Math.round(this.y)+"px"; 
	}
}

function dw_shiftBy(x,y) {
	this.shiftTo(this.x+x,this.y+y);
}

function dw_writeLyr(cntnt) {
	if (typeof this.doc.innerHTML!="undefined") {
      this.doc.innerHTML = cntnt;
  } else if (document.layers) {
			this.doc.write(cntnt);
			this.doc.close();
  }
}

function dw_setBgClr(bg) {
	if (document.layers) this.doc.bgColor=bg;
	else this.css.backgroundColor=bg;
}

// assign methods 
dynObj.prototype.show = dw_show;
dynObj.prototype.hide = dw_hide;
dynObj.prototype.shiftTo = dw_shiftTo;
dynObj.prototype.shiftBy = dw_shiftBy;
dynObj.prototype.writeLyr = dw_writeLyr;
dynObj.prototype.setBgClr=dw_setBgClr;

// Striped Table

// this function is need to work around 
// a bug in IE related to element attributes
function hasClass(obj) {
var result = false;
if (obj.getAttributeNode("class") != null) {
result = obj.getAttributeNode("class").value;
}
return result;
}

 function stripe(id) {
 
// the flag we'll use to keep track of 
// whether the current row is odd or even
var even = false;

// if arguments are provided to specify the colours
// of the even & odd rows, then use the them;
// otherwise use the following defaults:
var evenColor = arguments[1] ? arguments[1] : "#fff";
var oddColor = arguments[2] ? arguments[2] : "#eee";

// obtain a reference to the desired table
// if no such table exists, abort
var table = document.getElementById(id);
if (! table) { return; }

// by definition, tables can have more than one tbody
// element, so we'll have to get the list of child
// &lt;tbody&gt;s 
var tbodies = table.getElementsByTagName("tbody");

// and iterate through them...
for (var h = 0; h < tbodies.length; h++) {

// find all the &lt;tr&gt; elements... 
var trs = tbodies[h].getElementsByTagName("tr");

// ... and iterate through them
for (var i = 0; i < trs.length; i++) {

// avoid rows that have a class attribute or backgroundColor style
if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {

// get all the cells in this row...
var tds = trs[i].getElementsByTagName("td");

// and iterate through them...
for (var j = 0; j < tds.length; j++) {

var mytd = tds[j];

// avoid cells that have a class attribute or backgroundColor style
if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
mytd.style.backgroundColor = even ? evenColor : oddColor;
}
}

// flip from odd to even, or vice-versa
even =  ! even;
}
else {
even = true;
}
}
}
}

function isValidEmail(address) {
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(address));
}

function swapImage(name, img) {
    var obj = document.getElementById(name);
    obj.src = img;
}