GE_Nav = function(el) {
	this.el = $(el);
	this.a = null;
	this.subNav = null;
	this.index = null;
	this.init();
}

GE_Nav.itemIndex = 0;;

GE_Nav.shimEl = null;

GE_Nav.searchedCurrentLiEl = false;

GE_Nav.prototype.init = function() {

	var hasChildren = this.el.hasClassName("hasChildren");

	if (hasChildren) {

		this.index = GE_Nav.itemIndex++;

		if (!/WebKit/i.test(navigator.userAgent)) { // sniff out Safari and disable drop-down menus
			this.el.observe("mouseover", this.doOver.bindAsEventListener(this) );
			this.el.observe("mouseout", this.doOut.bindAsEventListener(this) );
			this.el.observe("focus", this.show.bind(this) );
			this.el.observe("blur", this.hide.bind(this) );
		} else {
			// with drop-downs disabled, safari has -1px top margin shift because of lack of border.
			// these observes will remove that style on hover.
			this.el.observe("mouseover",function(){this.el.down().setStyle({backgroundPosition:'50% -24px'});}.bind(this));
			this.el.observe("mouseout",function(){this.el.down().setStyle({backgroundPosition:'50% 1px'});}.bind(this));
		}

		this.subNav = this.el.getElementsBySelector(".navSubItem")[0];

		if (this.subNav) {

			this.a = this.el.down().cloneNode(true);
			var li = $(document.createElement('li'));
			li.appendChild(this.a);
			if (this.el.hasClassName('currentItem') && !this.el.hasClassName('currentParent')) { li.addClassName('currentItem') }
			if(this.a.innerHTML != 'Submit an Idea' && this.a.innerHTML != 'Contact Information'){	//don't do this for submit an idea and contact info
				this.subNav.insertBefore(li,this.subNav.down());
			}
			var subNavWrapper = $(document.createElement('div'));
			subNavWrapper.addClassName('currentItem');
			if ($('ge_skipToContent')) subNavWrapper.appendChild($('ge_skipToContent'));
			subNavWrapper.appendChild(this.subNav);

			$("navigation").appendChild(subNavWrapper);
		}
	}
}

GE_Nav.prototype.doOver = function(e) {
	if (GE_detectMouseEnter(this.el,e)) {
		this.show();
	}
	Event.stop(e);
	return false;
}

GE_Nav.prototype.doOut = function(e) {
	if (GE_detectMouseLeave(this.el,e)) {
		this.hide();
	}
	Event.stop(e);
	return false;
}

GE_Nav.prototype.show = function() {
	this.el.addClassName('activeItem');

	var html = ddcontent[this.index];

	new Insertion.After(this.el.down(), html);

	var newEl = this.el.down().next();

	if (this.el.id=="nav_products_services") {
		var elGroupLI = newEl.immediateDescendants();
		// elGroupLI.pop().remove(); //remove this line to add last element (A-Z index) back
		var numLI = elGroupLI.length;
		var rowCount = 5; // Math.floor(numLI/3);
		// var remainder = numLI%3;
		var index = 0;
		for (var r=0;r<3;r++) {
			var elLI = Builder.node('li',{className:'navGroup'});
			var elGroupUL = Builder.node('ul');
			// var c = (0<remainder--)?rowCount+1:rowCount;
			for (var n=0;n<rowCount;n++) {
				if (index >= numLI) break;
				elGroupUL.appendChild(elGroupLI[index++]);
			}
			elLI.appendChild(elGroupUL);
			newEl.appendChild(elLI);
		}
	}

	if (/MSIE/i.test(navigator.userAgent)) {
		var shimEl = this.getShimEl();
		Position.clone(newEl, shimEl);
		shimEl.setStyle({zIndex:"1", visibility:"inherit" });
	}
}

GE_Nav.prototype.hide = function() {
	this.el.removeClassName('activeItem');

	var tmp = this.el.down().next();
	if (tmp) { tmp.remove(); }
	// this.el.down().next().remove();

	if (/MSIE/i.test(navigator.userAgent)) {
		this.getShimEl().setStyle({visibility:"hidden"});
	}
}

GE_Nav.prototype.getShimEl = function() {
	if (GE_Nav.shimEl==null) {
		GE_Nav.shimEl = $(Builder.node( "iframe", {style:"visibility:hidden;background:white;position:absolute; top:0px; left:0px;", frameBorder:"0", scrolling:"no"}));

		//GE_Nav.shimEl.src="://";
		GE_Nav.shimEl.src=GE_baselink+"html_view/blank.htm";
		//GE_Nav.shimEl.setOpacity(.01);
		document.body.appendChild(GE_Nav.shimEl);
	}
	return GE_Nav.shimEl;
}


GE_Main.mapFnToCSS("navItem",GE_Nav);