collapseDelay=0.5;
navSet=null;
navCollapse=null;

function fnOpenWindow(url,parameters)
{
	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();
}



function fnNavIn(evt)
{
	if (evt)
		evt.stopPropagation();
	if (window.event)
		event.cancelBubble=true;

	if (navCollapse) {
		clearTimeout(navCollapse);
		navCollapse=null;
	}
	fnNavSet(this);
}

function fnNavOut(evt)
{
	if (evt)
		evt.stopPropagation();
	if (window.event)
		event.cancelBubble=true;
	if (navSet)
		navCollapse = setTimeout(fnNavUnset, collapseDelay*1000 );
}

function fnNavSet(oElement)
{
	var newNavSet=null;
	while ( (oElement)&&(oElement.id!='nav')&&(oElement.parentNode)&&(oElement.parentNode!=oElement) ) {
		if ( oElement.tagName.toLowerCase()=='li' ) {
			if (isDescendantOf(oElement,navSet))
				return;
			fnNavShow(oElement);
			newNavSet=oElement;
			break;
		}
		oElement=oElement.parentNode;
	}

	if (navSet)
		fnNavUnshow(navSet);

	navSet=newNavSet;
}

function fnNavUnset()
{
	if (navSet==null)
		return;

	fnNavUnshow(navSet);
	navSet=null;
}

function fnNavShow(oNode)
{
	if (oNode.className!='set')
		oNode.storeClassName=oNode.className;
	oNode.className='set';
}
function fnNavUnshow(oNode)
{
	oNode.className=(oNode.storeClassName) ? oNode.storeClassName:'';
}

function isDescendantOf(node,parent)
{
	if (!parent)
		return false;
	while ( (node)&&(node.id!='nav')&&(node.parentNode)&&(node.parentNode!=node) ) {
		if ( node==parent )
			return true;
		node=node.parentNode;
	}
	return false;
}

function fnPrint(){
	if( window.print ){
		window.print();		
	}
	else {
		alert('Veuillez utiliser la fonction "imprimer" de votre navigateur.\n');
	}
	return false;
}

function fnInit()
{
	if (!document.getElementById)
		return;

	var oNav=null;
	if (document.getElementById('nav'))
		oNav=document.getElementById('nav');

	if (oNav!=null) {
		var aItems=oNav.getElementsByTagName('A');		
		for (var i=0;i<aItems.length;i++) {
			if( (aItems[i].parentNode.parentNode.id!="services") && (aItems[i].parentNode.parentNode.id!="requests") ){
				aItems[i].onfocus=fnNavIn;
				aItems[i].onblur=fnNavOut;
				aItems[i].onmouseover=fnNavIn;
				aItems[i].onmouseout=fnNavOut;			
				var oElement=aItems[i].parentNode;			
				oElement.onfocus=fnNavIn;
				oElement.onblur=fnNavOut;
				oElement.onmouseover=fnNavIn;
				oElement.onmouseout=fnNavOut;
			}			
		}
	}

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

		//print	
		if( (allA[i].className == "print") || (allA[i].parentNode.className == "print") ) {
			allA[i].onclick = function () {return fnPrint();}
		}
	}	

}


window.onload=fnInit;