iconsIn=new Array();
iconSet=null;
serviceSet=null;
navSet=null;
navCollapse=null;
collapseDelay=0.5;
initComplete=false;

function setLinks() {	
	if (document.getElementsByTagName) {
		var allA = document.getElementsByTagName('A');
		for(i=0;i<allA.length;i++) {
			if (allA[i].rel == "bookmark") {
				allA[i].onclick = function(evt) {
					if ((evt)&&(evt.ctrlKey))
						return;
					window.open(this.href);
					return false;
				}
			}
		}
	}
}

function checkMenuState()
{
	if (initComplete==false) {
		if ( (document.getElementById)&&(document.getElementById('navmain')) )
			fnInit();
		else
			setTimeout(checkMenuState, 1000 );
	}
}

function fnInit()
{	
	var oNavMain=null;
	if ( (document.getElementById)&&(document.getElementById('navmain')) )
		oNavMain=document.getElementById('navmain');
	if (oNavMain!=null)
	{
		var aItems=oNavMain.getElementsByTagName('DIV');
		for (var i=0;i<aItems.length;i++)
		{
			if (aItems[i].className!='holder')
				continue;

			aItems[i].style.position='absolute';
			aItems[i].style.visibility='hidden';
			aItems[i].style.whiteSpace='nowrap';
		}

		aItems=oNavMain.getElementsByTagName('A');
		for (var i=0;i<aItems.length;i++)
		{
			aItems[i].onmouseover=fnNavIn;
			aItems[i].onfocus=fnNavIn;
			aItems[i].onmouseout=fnNavOut;
			aItems[i].onblur=fnNavOut;
		}
	}

	var oRefs=null;
	if ( (document.getElementById)&&(document.getElementById('references')) )
		oRefs=document.getElementById('references');
	if (oRefs!=null)
	{
		var aIcons=oRefs.getElementsByTagName('A');
		for (var i=0;i<aIcons.length;i++)
		{
			var oOwner=aIcons[i];
			if (oOwner.className!='icon')
				continue;
			if (iconSet==null)
				fnIconSet(oOwner)
			oOwner.onmouseover=fnIconIn;
			oOwner.onfocus=fnIconIn;
		}
	}


	var oServices=null;
	if ( (document.getElementById)&&(document.getElementById('services')) )
		oServices=document.getElementById('services');
	if (oServices!=null)
	{
		var aItems=oServices.getElementsByTagName('LI');
		for (var i=0;i<aItems.length;i++)
		{
			var oOwner=aItems[i];
			oOwner.onmouseover=fnServiceIn;
			if (serviceSet==null)
				fnServiceSet(oOwner)
		}
	}		

	initComplete=true;
	setLinks();
}

function fnNavIn()
{
	fnNavSet(this);
}

function fnNavOut()
{
	if (navSet)
		navCollapse = setTimeout(fnNavUnset, collapseDelay*1000 );
}

function fnNavSet(oElement)
{
	if (navCollapse)
	{
		clearTimeout(navCollapse);
		navCollapse=null;
	}


	while ( (oElement)&&(oElement.tagName.toLowerCase()!='li')&&(oElement.parentNode)&&(oElement.parentNode!=oElement) )
	{
		oElement=oElement.parentNode;
	}

	var oSublevel=null;
	for (var i=0;i<oElement.childNodes.length;i++)
	{
		if ((oElement.childNodes[i].tagName)&&(oElement.childNodes[i].tagName.toLowerCase()=='div')&&(oElement.childNodes[i].style.position=='absolute'))
		{
			oSublevel=oElement.childNodes[i];
			break;
		}
	}
	if ( (oSublevel==null)&&(navSet==oElement.parentNode.parentNode) )
		return;

	if (oSublevel==navSet)
		return;

	fnNavUnset();

	if (oSublevel)
		oSublevel.style.visibility='visible';
	navSet=oSublevel;
}

function fnNavUnset()
{
	if (navSet)
		navSet.style.visibility='hidden';
	navSet=null;
}


function fnServiceIn()
{
	fnServiceSet(this);
}
function fnServiceSet(oElement)
{
	while ( (oElement)&&(oElement.tagName.toLowerCase()!='li')&&(oElement.parentNode)&&(oElement.parentNode!=oElement) )
	{
		oElement=oElement.parentNode;
	}

	var oFolded=null;
	if ((oElement)&&(oElement.tagName)&&(oElement.tagName.toLowerCase()=='li'))
	{
		for (var i=0;i<oElement.childNodes.length;i++)
		{
			if ((oElement.childNodes[i].className)&&(oElement.childNodes[i].className=='folded'))
				oFolded=oElement.childNodes[i];
		}
	}
	if (oFolded==null)
		return;

	if ( (serviceSet)&&(serviceSet!=oFolded) )
	{
		fnServiceUnset(serviceSet);
	}

	if (oFolded!=null)
		oFolded.style.display='block';
	serviceSet=oFolded;
}
function fnServiceUnset(oUnfolded)
{
	oUnfolded.style.display='none';
	serviceSet=null;
}



function fnIconIn()
{
	fnIconSet(this);
}

function fnIconSet(oIcon)
{
	if (oIcon==iconSet)
		return;
	if (iconSet)
		fnIconUnset(iconSet)

	var oImg=oIcon.childNodes[0];
	var outSrc=oImg.src;
	var inSrc=iconsIn[oImg.id];
	if (!inSrc)
		return;

	oImg.src=inSrc;
	iconsIn[oImg.id]=outSrc;
	oImg.style.top='5px';

	var oLI=oIcon.parentNode;
	var oDetail=null;
	for (var i=0;i<oLI.childNodes.length;i++)
	{
		if ((oLI.childNodes[i].className)&&(oLI.childNodes[i].className=='detail'))
			oDetail=oLI.childNodes[i];
	}
	if (oDetail)
		oDetail.style.visibility='visible';

	iconSet=oIcon;
}

function fnIconUnset(oIcon)
{
	var oImg=oIcon.childNodes[0];
	var outSrc=iconsIn[oImg.id];
	var inSrc=oImg.src;

	oImg.src=outSrc;
	iconsIn[oImg.id]=inSrc;
	oImg.style.top='0';

	var oLI=oIcon.parentNode;
	var oDetail=null;
	for (var i=0;i<oLI.childNodes.length;i++)
	{
		if ((oLI.childNodes[i].className)&&(oLI.childNodes[i].className=='detail'))
			oDetail=oLI.childNodes[i];
	}
	if (oDetail)
		oDetail.style.visibility='hidden';
}


function fnOpenWindow(url,parameters)
{
	parameters=parameters.replace(/\s+/g,'');

	var aParameters=parameters.split(',');
	var data=new Array();
	for (var i=0;i<aParameters.length;i++) {
		var pr=aParameters[i];
		var key = pr.substr(0,pr.indexOf('='));
		var value=pr.substr(pr.indexOf('=')+1);
		data[key]=value;
	}

	if ( (data['hposition'])&&(data['width'])&&(data['hposition']!='system') )
	{
		var posX=null;
		if (data['hposition']=='left')
		{
			posX=0;
		}
		if ( (window.screen)&&(window.screen.availWidth) )
		{
			if (data['hposition']=='center')
				posX=(window.screen.availWidth-data['width'])/2;
			if (data['hposition']=='right')
				posX=window.screen.availWidth-data['width'];
		}

		if (posX!=null)
			parameters+=",left="+parseInt(posX);
	}

	if ( (data['vposition'])&&(data['height'])&&(data['vposition']!='system') )
	{
		var posY=null;
		if (data['vposition']=='top')
		{
			posY=0;
		}
		if ( (window.screen)&&(window.screen.availHeight) )
		{
			if (data['vposition']=='center')
				posY=(window.screen.availHeight-data['height'])/2;
			if (data['vposition']=='bottom')
				posY=window.screen.availHeight-data['height'];
		}

		if (posY!=null)
			parameters+=",top="+parseInt(posY);
	}


	var oWnd=window.open(url,'',parameters);
	oWnd.focus();
}

window.onload=fnInit;
checkMenuState();
