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

DBMI_Nav.itemIndex = 0;

DBMI_Nav.shimEl = null;


DBMI_Nav.prototype.init = function() {

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

	if (hasChildren) {

		this.index = DBMI_Nav.itemIndex++;

			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) );


		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') }
	
			var subNavWrapper = $(document.createElement('div'));
			subNavWrapper.addClassName('currentItem');
			if ($('dbmi_skipToContent')) subNavWrapper.appendChild($('dbmi_skipToContent'));
			subNavWrapper.appendChild(this.subNav);

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

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

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

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

	var html = ddcontent[this.index];

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

	
}

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

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

DBMI_Nav.prototype.getShimEl = function() {
	if (DBMI_Nav.shimEl==null) {
		DBMI_Nav.shimEl = new Element( "iframe", {style:"visibility:hidden;background:white;position:absolute; top:0px; left:0px;", frameBorder:"0", scrolling:"no"});
		
	}
	return DBMI_Nav.shimEl;
}


DBMI_Main.mapFnToCSS("navItem",DBMI_Nav);
