var delay = 400;
var timeout;
var timeout2;
var nbItems = 0;
var nbSubItems = 0;
var idPereActif = '';

function showMenu(num)
{
	id = 'menu_' + num;
	idpere = 'menup_' + num;
	idlink = 'menu-text_' + num;
	
	if(num==1)
		var decalage = 24;
	else
		var decalage = 2;
	
	hideAll();
	cancelDelay();
	el = getElement(id);
	
	var pos = getPos(document.getElementById(idpere));
	if(window.innerWidth)
	{
		largeurFenetre = window.innerWidth;
	}
	else
	{
		largeurFenetre = document.body.offsetWidth;
	}
	if(largeurFenetre < 980)
	{
		largeurFenetre = 980;
	}
	if((pos.x + 100) >= largeurFenetre)
	{
		el.left = (pos.x - decalage - 75) + 'px';
	}
	else
	{
		el.left = (pos.x - decalage) + 'px';
	}
	el.top = (pos.y + 21) + 'px';
	document.getElementById(idlink).className='menu-text-highlight';
	document.getElementById(id).className='menu-on';
}

function showSubmenu(num, numPere)
{
	id = 'submenu_' + num;
	idpere = 'menu_' + numPere;
	
	hideAllSub();
	cancelDelay();
	cancelSubDelay();
	el = getElement(id);
	
	var pos = getPos(document.getElementById(idpere));
	var largeur = document.getElementById(idpere).offsetWidth - 6;
	document.getElementById(idpere).className='sub-menu-ss-actif';
	idPereActif = idpere;
	document.getElementById(id).className='submenu-on';
	if(window.innerWidth)
	{
		largeurFenetre = window.innerWidth;
	}
	else
	{
		largeurFenetre = document.body.offsetWidth;
	}
	if(largeurFenetre < 980)
	{
		largeurFenetre = 980;
	}
	if((pos.x + 300) >= largeurFenetre)
	{
		el.left = (pos.x - document.getElementById(id).offsetWidth) + 'px';
	}
	else
	{
		el.left = (pos.x + largeur) + 'px';
	}
	el.top = (pos.y - 3) + 'px';
}

function hideAll()
{
	hideAllSub();
	for(var i=1; i<=nbItems; i++)
	{
		document.getElementById('menu-text_' + i).className='menu-text';
		document.getElementById('menu_' + i).className='menu-off';
	}
}

function hideAllSub()
{
	for(var i=1; i<=nbSubItems; i++)
	{
		document.getElementById('submenu_' + i).className='submenu-off';
	}
	if(idPereActif != '')
	{
		document.getElementById(idPereActif).className='sub-menu-ss';
		idPereActif = '';
	}
}

function hideDelay()
{
	timeout = setTimeout('hideAll()', delay);
}

function hideSubDelay()
{
	timeout2 = setTimeout('hideAllSub()', delay);
}

function cancelDelay()
{
	if(timeout)
		clearTimeout(timeout);
}

function cancelSubDelay()
{
	cancelDelay();
	if(timeout2)
		clearTimeout(timeout2);
}

function getPos(element)
{
	for(var lx=0,ly=0; element!=null; lx+=element.offsetLeft,ly+=element.offsetTop,element=element.offsetParent)
		;
	return {x:lx,y:ly};
}

function getElement(id)
{
	// getElementById ==> Navigateurs recents supportant le DHTML
	// document.layers ==> Netscape 4.x
	el = document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : document.layers[id];
	el = document.layers ? el : el.style;
	return el;
}

/* FONCTIONS UTILISEES POUR LES ICONES */
var descriptionText='';
var timeout2;

function descriptionShow(nom, descriptionText)
{
	descriptionHideNoDelay();
	clearTimeout(timeout2);
		
	var posx = document.getElementById('icon_' + nom).offsetLeft + 25;

	switch(nom)
	{
	case 'liste':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'news':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'medias':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'tests':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'dossiers':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'tutoriels':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'astuces':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'avis':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'demandes_avis':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'prix':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'pa':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	case 'forums':
		document.getElementById('description-arrow').style.left = posx + 'px';
		break;
	}
	document.getElementById('description-arrow').style.visibility = 'visible';
	document.getElementById('description-texte').innerHTML = descriptionText;
}

function descriptionHide()
{
	timeout2 = setTimeout('descriptionHideNoDelay()', delay);
}

function descriptionHideNoDelay()
{
	document.getElementById('description-arrow').style.visibility='hidden';
	document.getElementById('description-texte').innerHTML = descriptionText;
}

function setDefaultDescriptionText(text)
{
	descriptionText = text;
	document.getElementById('description-texte').innerHTML = descriptionText;
}

function changeTestSommaire()
{
	if(document.forms['form_sommaire'].elements['idproduit'])
	{
		window.location.href = '/produits/tests/index,idproduit,' + document.forms['form_sommaire'].elements['idproduit'].value + ',page,' + document.forms['form_sommaire'].elements['numero_page'].value + '.html';
	}
}

function changeDossierSommaire()
{
	if(document.forms['form_sommaire'].elements['idossier'])
	{
		window.location.href = '/apprendre/dossiers/index,idossier,' + document.forms['form_sommaire'].elements['idossier'].value + ',page,' + document.forms['form_sommaire'].elements['numero_page'].value + '.html';
	}
}

function findobj(n, d)
{
	var p,i,x;
	if(!d)
		d=document;
	if((p=n.indexOf("?"))>0&&parent.frames.length)
	{
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all)
		x=d.all[n];
	for (i=0;!x&&i<d.forms.length;i++)
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++)
		x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById)
		x=d.getElementById(n);
	return x;
}
