var NAVMENUOBJECT = new Array();

function navregister(navid)
{
	NAVMENUOBJECT[NAVMENUOBJECT.length] = navid;
}

function AtLantis_Navmenu()
{
	this.lastMenu = -1;
	this.in_area = false;
	this.menu_active = false;
	this.menugroup = '';
}

AtLantis_Navmenu.prototype.init = function()
{
	for (var i = 0; i < NAVMENUOBJECT.length; i++)
	{
		var linkobject = YAHOO.util.Dom.get(NAVMENUOBJECT[i]);
		if (!linkobject)
		{
			continue;
		}

		var menuobject = YAHOO.util.Dom.get(NAVMENUOBJECT[i] + '_menu');
		if (!menuobject)
		{
			this.set_events_menu(linkobject, false);
			this.set_menu_init(linkobject, false);
			continue;
		}

		var divtags = YAHOO.util.Dom.getElementsBy(function(){ return true; }, 'div', menuobject);
		if (divtags.length == 0)
		{
			this.set_menu_init(linkobject, false);
			this.set_events_menu(linkobject, false);
			continue;
		}

		this.set_menu_init(linkobject, true);
		this.set_events_menu(linkobject, true);

		for (var k = 0; k < divtags.length; k++)
		{
			this.set_events_links(divtags[k]);
		}
	}

	YAHOO.util.Event.addListener(window, 'resize', this.hide_menu_active, this);
	YAHOO.util.Event.addListener(document, 'click', this.document_click, this);
};

AtLantis_Navmenu.prototype.set_menu_init = function(obj, init)
{
	obj.menuInit = init ? true : false;
	if (init)
	{
		obj.menuId = obj.id + '_menu';
	}
};


AtLantis_Navmenu.prototype.set_events_menu = function(obj, preventStop)
{
	YAHOO.util.Dom.addClass(obj, 'nav-links');
	YAHOO.util.Event.addListener(obj, 'mouseover', this.menu_mouseover, this);
	YAHOO.util.Event.addListener(obj, 'mouseout', this.menu_mouseout, this);
	YAHOO.util.Event.addListener(obj, 'click', this.menu_click, this);

	if (preventStop)
	{
		var anchor = YAHOO.util.Dom.getElementsBy(function(){ return true; }, 'a', obj)[0];
		YAHOO.util.Event.addListener(anchor, 'click', function(e, _this){ YAHOO.util.Event.preventDefault(e); }, this);

		YAHOO.util.Dom.addClass(obj.menuId, 'nav-dhtml');
	}
};

AtLantis_Navmenu.prototype.set_events_links = function(obj)
{
	YAHOO.util.Dom.addClass(obj, 'nav-dhtml-link');
	YAHOO.util.Event.addListener(obj, 'mouseover', this.link_mouseover, this);
	YAHOO.util.Event.addListener(obj, 'mouseout', this.link_mouseout, this);
	YAHOO.util.Event.addListener(obj, 'click', this.link_click);
};

AtLantis_Navmenu.prototype.menu_mouseover = function(e, _this)
{
	if (!_this.menu_active)
	{
		YAHOO.util.Dom.replaceClass(this, 'nav-link', 'nav-link-hover');
	}

	_this.in_area = true;
};

AtLantis_Navmenu.prototype.menu_mouseout = function(e, _this)
{
	if (!_this.menu_active)
	{
		YAHOO.util.Dom.replaceClass(this, 'nav-link-hover', 'nav-link');
	}

	_this.in_area = false;
};

AtLantis_Navmenu.prototype.menu_click = function(e, _this)
{
	_this.show_menu(this);
	_this.set_position(this);
	_this.menugroup = this.id;
	if (this.className != 'nav-link-hover')
	{
		YAHOO.util.Dom.replaceClass(this, 'nav-link', 'nav-link-hover');
	}
};

AtLantis_Navmenu.prototype.link_mouseover = function(e, _this)
{
	YAHOO.util.Dom.replaceClass(this, 'nav-dhtml-link', 'nav-dhtml-link-hover');
	_this.in_area = true;
};

AtLantis_Navmenu.prototype.link_mouseout = function(e, _this)
{
	YAHOO.util.Dom.replaceClass(this, 'nav-dhtml-link-hover', 'nav-dhtml-link');
	_this.in_area = false;
};

AtLantis_Navmenu.prototype.show_menu = function(_this)
{
	if (this.lastMenu !== -1)
	{
		this.hide_menu(this.lastMenu);
	}
	
	YAHOO.util.Dom.get(_this.menuId).style.display = '';
	this.lastMenu = _this.id;
	this.menu_active = true;
};

AtLantis_Navmenu.prototype.set_position = function(_this)
{
	if (_this.menuInit)
	{
		var menuobj = YAHOO.util.Dom.get(_this.id);
		var coord = YAHOO.util.Dom.getXY(menuobj);
		var menu = YAHOO.util.Dom.get(_this.menuId);

		if (menu.offsetWidth > menuobj.offsetWidth)
		{
			var newx = Math.round((menu.offsetWidth - menuobj.offsetWidth) / 2) * -1;
		}
		else if (menu.offsetWidth < menuobj.offsetWidth)
		{
			var newx = Math.ceil((menuobj.offsetWidth - menu.offsetWidth) / 2);
		}

		coord[1] += menuobj.offsetHeight;
		coord[0] += newx;

		YAHOO.util.Dom.setXY(menu, coord, false);
	}
};

AtLantis_Navmenu.prototype.hide_menu = function(menuId)
{
	YAHOO.util.Dom.get(menuId + '_menu').style.display = 'none';
	this.lastMenu = -1;
	this.menu_active = false;
	if (this.menugroup)
	{
		YAHOO.util.Dom.replaceClass(this.menugroup, 'nav-link-hover', 'nav-link');
		this.menugroup = '';
	}
};

AtLantis_Navmenu.prototype.hide_menu_active = function(e, _this)
{
	if (_this.lastMenu !== -1)
	{
		_this.hide_menu(_this.lastMenu);
	}
};

AtLantis_Navmenu.prototype.document_click = function(e, _this)
{
	if (!_this.in_area && _this.lastMenu !== -1)
	{
		_this.hide_menu_active(e, _this);
	}
};

AtLantis_Navmenu.prototype.secnav_mouseover = function(e)
{
	YAHOO.util.Dom.replaceClass(this, 'menubits', 'menubits-hover');
};

AtLantis_Navmenu.prototype.secnav_mouseout = function(e)
{
	YAHOO.util.Dom.replaceClass(this, 'menubits-hover', 'menubits');
};

AtLantis_Navmenu.prototype.left_nav_init = function(e)
{
	var links = YAHOO.util.Dom.getElementsByClassName('menubits', 'div', 'menu-content');
	for (var i = 0; i < links.length; i++)
	{
		YAHOO.util.Event.on(links[i], 'mouseover', AtLantis_Navmenu.prototype.secnav_mouseover);
		YAHOO.util.Event.on(links[i], 'mouseout', AtLantis_Navmenu.prototype.secnav_mouseout);
	}
}

YAHOO.util.Event.onDOMReady(function(){ var navmenu = new AtLantis_Navmenu(); navmenu.init(); navmenu.left_nav_init(); });