
var __current_shown_nav = 0;
var __nav_timeout = null;

var __homepromo_timeout = null;

var _ua = UC(navigator.userAgent);
var _mac = (_ua.indexOf("MAC") != -1) ? true : false;
var _o = (_ua.indexOf("OPERA") != -1) ? true : false;
var _ie = ((document.all&&!_o) ? true : false);

function showNav(id)
{
  var oNAV, oCELL, i, w, j, oTMP, k, l, t;


	if(__current_shown_nav)
	{
		clearTimeout(__nav_timeout);
		_GID('nav_id_' + __current_shown_nav).setAttribute('is_hover', '0');
		if((__current_shown_nav != id) || (_ie && _mac))
		{
			hideNav2(__current_shown_nav);
		}
	}
			
	oNAV = _GID('nav_id_' + id);
	oCELL = null;

	oTMP = oNAV.getElementsByTagName('LI');
	if(oTMP)
	{
	        if(oTMP.length > 0)
	        {
			oNAV.style.display = 'block';
		}
	}



	k = 0;
	if(!oCELL)
	{

		oTMP = _GID('mainNav').getElementsByTagName('LI');

		
		for(i=0; i<oTMP.length; i++)
		{

		        t = oTMP[i].getAttribute('NavId') + '';
			if(t == 'Nav' + id)
			{
				oCELL = oTMP[i];
				break;
			}
			if(t.substr(0, 3) == 'Nav')
			{
				k += (oTMP[i].clientWidth ? oTMP[i].clientWidth : oTMP[i].offsetWidth);
			}
		}
	}

	if(oCELL)
	{

/*
	                        w = 129;
				oTMP = oCELL.getElementsByTagName('LI');
				for(var n=0; n<oTMP.length; n++)
				{
					if(oTMP[n].clientWidth > w)
					{
						w = oTMP[n].clientWidth;
					}
				}
				for(n=0; n<oTMP.length; n++)
				{
					oTMP[n].style.width = w + 'px';
				}
		oNAV.style.width = '160' + 'px';
*/
		w = 0;
//		w = _GID('wrapper').offsetLeft + (oCELL.getAttribute('nav_offset')-1) * 120;
//		w = _GID('wrapper').left + 0;

		oNAV.style.left = _GID('wrapper').offsetLeft + (_ie&&_mac?0:8) + k + (k>0?-1:0) + 'px';
		oNAV.style.top = _GID('header').offsetHeight + 'px';
		
	}

	__current_shown_nav = id;


	oNAV.setAttribute('is_hover', '1');

	if(!_ie || _mac)
	{
		oTMP = document.getElementsByTagName('OBJECT');
		for(i=0; i<oTMP.length; i++)
		{
			if(oTMP[i].id == 'FlashItem')
			{
				oTMP[i].style.visibility = 'hidden';
			}
		}
	}
}


function hideNav(id)
{
	if(!__current_shown_nav) return;
	
	_GID('nav_id_' + id).setAttribute('is_hover', '0');

	__nav_timeout = setTimeout("hideNav2('"+id+"')", 100);
}


function hideNav2(id)
{
  var oNAV;

	oNAV = _GID('nav_id_' + id);


	if(typeof(oNAV) != 'object') return;
			

	if(oNAV.getAttribute('is_hover') == '1') return;


	oNAV.style.display = 'none';
	__current_shown_nav = false;


	if(!_ie || _mac)
	{
		oTMP = document.getElementsByTagName('OBJECT');
		for(i=0; i<oTMP.length; i++)
		{
			if(oTMP[i].id == 'FlashItem')
			{
				oTMP[i].style.visibility = 'visible';
			}
		}
	}
}



function onResizeNav()
{
	if(__current_shown_nav)
	{
		showNav(__current_shown_nav);
	}
}


function hideNavAll()
{
	if(__current_shown_nav)
	{
	        hideNav(__current_shown_nav);
	}
}
		
		
function navInit()
{
  var i, j, k, m, n, w, id, oNAV, oSUBNAV, oCELL, fn, o, t, oTMP;

        oNAV = _GID('mainNav').childNodes;

        m = 0;
	for(i=0; i<oNAV.length; i++)
	{
		oCELL = oNAV[i];

		if(UC(oNAV[i].tagName) == 'LI')
		{
			m++;
		}

		oSUBNAV = oNAV[i].childNodes;
		for(j=0; j<oSUBNAV.length; j++)
		{


			if(UC(oSUBNAV[j].tagName) == 'UL')
			{
				k = (i*1000 + j);

				id = 'nav_id_' + k;

				oSUBNAV[j].id = id;


				oSUBNAV[j].onmouseover = function (){showNav(this.getAttribute('nav_id'))};
				oSUBNAV[j].onmouseout = function (){hideNav(this.getAttribute('nav_id'));};
				oSUBNAV[j].setAttribute('nav_id', k);

//				oCELL.id = 'Nav' + k;
				oCELL.setAttribute('NavId', 'Nav' + k);

				oSUBNAV[j].style.left = (_GID('wrapper').offsetLeft + (m-1) * 120) + 'px';

				w = 129;

				oTMP = oSUBNAV[j].getElementsByTagName('A');
				for(n=0; n<oTMP.length; n++)
				{
					if(oTMP[n].clientWidth > w)
					{
						w = oTMP.clientWidth;
					}
				}

				
				oCELL.setAttribute('nav_offset', m);
				oCELL.setAttribute('nav_width', w);

				oCELL.onmouseover = function (){showNav(this.getAttribute('nav_id'));};
				oCELL.onmouseout = function (){hideNav(this.getAttribute('nav_id'));};
				oCELL.setAttribute('nav_id', k);
			}
		}
	}
	
	try{
		_GID('fmSearchText').focus();
	}catch(e){};
}

function goSolutionsFinder()
{
  var o, url;

	o = _GID('goTo');
	url = o.options[o.selectedIndex].value;

	document.location = url;
}


addHook('WindowOnResize', 'onResizeNav');
addHook('DocumentOnClick', 'hideNavAll');
addHook('WindowOnLoad', 'navInit');
