var currentActiveItem = null;
var _nodes = null;
var _promo = null;

function startHovers() {

	for (var i=0; i<_nodes.length; i++) {

	
		_nodes[i].onmouseover = function() {
					
			for (var k=0; k<_nodes.length; k++)
			{
				if (_nodes[k].className.indexOf("active") != -1)
				{
					currentActiveItem = _nodes[k];
				}
				_nodes[k].className = _nodes[k].className.replace("active", "");
			}
			if (this.className.indexOf("active") == -1)
			{
				this.className += " active";
			}
			return false;
		}
		
		_nodes[i].onmouseout = function()
		{
			this.className = this.className.replace("active", "");
			return false;
		}
	}

_promo.onmouseout = function()	{
		for (var k=0; k<_nodes.length; k++)
		{
			_nodes[k].className = _nodes[k].className.replace("active", "");
		}
		
		if (currentActiveItem)
		{
			if (currentActiveItem.className.indexOf("active") == -1)
			{
				currentActiveItem.className += " active";
			}
		}
	}

}

function initPromo () {
	
	_promo = document.getElementById("promo");
	if (_promo)
	{
		_nodes = _promo.getElementsByTagName("li");
		startHovers();
	}
}

function initNavigation() {
	var _nav = document.getElementById("navigation-main");
	var _lis = _nav.getElementsByTagName("li");
	for (i = 0; i<_lis.length; i++)
	{
		var _link = _lis[i].getElementsByTagName("a");
		if (_link[0])
		{
			var _hover = _link[0].getElementsByTagName("span");
			
			if (_hover[0])
			{
				_lis[i]._link = _link[0];
				_lis[i]._link.first = _link[0].innerHTML;
				_lis[i]._link.second = _hover[0].innerHTML;
				_lis[i]._link.second_class = _hover[0].className;
			}
		}
		_lis[i].onmouseover = function()
		{
			if (this._link)
			{
				this._link.innerHTML = this._link.second;
				this.className += " "+ this._link.second_class;
			}
			var _sub = this.getElementsByTagName("ul");
			if (_sub[0])
			{
				if (this.className.indexOf("hover") == -1)
				{
					this.className += " hover";
				}
			}
		}
		_lis[i].onmouseout = function()
		{
			if (this._link)
			{
				this._link.innerHTML = this._link.first;
				this.className = this.className.replace(this._link.second_class, "");
			}
			this.className = this.className.replace("hover", "");
		}
	}
}

if (window.addEventListener) {
	window.addEventListener("load", initPromo, false);
	window.addEventListener("load", initNavigation, false);
}
else if (window.attachEvent) {
	window.attachEvent("onload", initPromo);
	window.attachEvent("onload", initNavigation);
}