var theTime;
var timer;
function createXMLHttpRequest() {
	if ( window.XMLHttpRequest ) return new XMLHttpRequest();
	else if ( window.ActiveXObject ) return new ActiveXObject("Microsoft.XMLHTTP");
	else alert("ActiveX Error.");  return null;
}
function init(){
	window.moveTo(0,0);
	if (document.getElementById || document.all){
		window.resizeTo(screen.availWidth, screen.availHeight);
	}else if (document.layers){
		if (window.outerHeight<screen.availHeight || window.outerWidth<screen.availWidth){
			window.outerHeight = screen.availHeight;
			window.outerWidth = screen.availWidth;
		}
	}
}
function fondOver(){
	document.onmousemove=stockTime;
	timer = window.setInterval("verifTime()",1500);
}
function fondOut(){
	document.onmousemove=null;
	clearInterval(timer);
}
function stockTime(e) {
	currentTime=new Date();
	theTime=currentTime.getTime();
	document.getElementById('fond').getElementsByTagName('a')[0].style.cursor='default';
	showBulle();
	placeBulle(e);
	hideBulle();
}
function verifTime() {
	currentTime=new Date();
	var timeNow=currentTime.getTime();
	if (timeNow-theTime>1500){
		document.getElementById('fond').getElementsByTagName('a')[0].style.cursor='pointer';
		showBulle();
	}
}
function resizeFond(ratio){
	var availHeight;
	var availWidth;
	if(typeof(window.innerWidth) == 'number'){
		availHeight = window.innerHeight;
		availWidth = window.innerWidth;
	}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		availHeight = document.documentElement.clientHeight;
		availWidth = document.documentElement.clientWidth;
	}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		availHeight = document.body.clientHeight;
		availWidth = document.body.clientWidth;
	}
	document.getElementById('fond').style.top = document.getElementById('fond').style.left = '0px';
	if(availWidth/availHeight>ratio){
		W = availWidth+'px';
		H = availWidth/ratio+'px';
	}else{
		W = availHeight*ratio+'px';
		H = availHeight+'px';
	}
	document.getElementById('fond').getElementsByTagName('img')[0].style.width = W;
	document.getElementById('fond').getElementsByTagName('img')[0].style.height = H;
}
function resizeCentre(){
	var availHeight;
	var availWidth;
	if(typeof(window.innerWidth) == 'number'){
		availHeight = window.innerHeight;
		availWidth = window.innerWidth;
	}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		availHeight = document.documentElement.clientHeight;
		availWidth = document.documentElement.clientWidth;
	}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		availHeight = document.body.clientHeight;
		availWidth = document.body.clientWidth;
	}
	document.getElementById('centre').style.height = availHeight+'px';
	//if(availWidth-228>770){
	document.getElementById('centre').style.width = (availWidth-228)+'px';
	/*}else{
		document.getElementById('centre').style.width = '765px';
	}*/
	var anchor = window.location.hash;
	if(anchor){
		var statuts = document.getElementById('sousmenu').getElementsByTagName('a');
		for(i=0; i<statuts.length; i++){
			var ancre = statuts[i].href.split('#');
			if('#'+ancre[1]==anchor){
				statuts[i].onclick();
				break;
			}
		}
	}else{
		if(!document.getElementById('sousmenu').getElementsByTagName('a')[0] || document.getElementById('sousmenu').getElementsByTagName('a')[0].innerHTML!="MENU"){
			changeStatut('');
		}
	}
}
function showMembre(type, id, montre){
	switch (type){
		case 'all' :
			var titre = document.getElementById('titre'+id);
			var lien = document.getElementById('lien'+id);
			if(titre && lien){
				if(montre){
					if(lien.style.display=='none'){
						titre.style.display=lien.style.display='';
						var membres = document.getElementById('centre').getElementsByTagName('div');
						for(i=0; i<membres.length; i++){
							if(membres[i].id!='membre'+id && membres[i].className!='clean' && membres[i].className!='marge'){
								if(document.all){
									membres[i].getElementsByTagName('img')[0].style.filter='alpha(opacity = 50)';
								}else{
									membres[i].getElementsByTagName('img')[0].style.opacity=0.5;
								}
							}else if(membres[i].id=='membre'+id){
								if(document.all){
									membres[i].getElementsByTagName('img')[0].style.filter='alpha(opacity = 100)';
								}else{
									membres[i].getElementsByTagName('img')[0].style.opacity=1;
								}
							}
						}
						var p = document.getElementById('infos').getElementsByTagName('p');
						for(i=0; i<p.length; i++){
							if(p[i].id!='titre'+id && p[i].id!='lien'+id){
								p[i].style.display='none';
							}
						}
					}else{
						showMembre('all', 0, false);
					}
				}
			}else if(id==0){
				if(!montre){
					var membres = document.getElementById('centre').getElementsByTagName('div');
					for(i=0; i<membres.length; i++){
						if(membres[i].className!='clean' && membres[i].className!='marge'){
							if(document.all){
								membres[i].getElementsByTagName('img')[0].style.filter='alpha(opacity = 100)';
							}else{
								membres[i].getElementsByTagName('img')[0].style.opacity=1;
							}
						}
					}
					var p = document.getElementById('infos').getElementsByTagName('p');
					for(i=0; i<p.length; i++){
						p[i].style.display='none';
					}
				}
			}
		break;
		case 'titre' :
			var titre = document.getElementById('titre'+id);
			var membre = document.getElementById('membre'+id).getElementsByTagName('img')[0];
			var ok = true;
			if(titre){
				if(document.all){
					if(membre.style.filter=='alpha(opacity = 50)'){
						ok = false;
					}
				}else{
					if(membre.style.opacity==0.5){
						ok = false;
					}
				}
				if(montre && ok){
					titre.style.display='';
				}else if(document.getElementById('lien'+id).style.display=='none'){
					titre.style.display='none';
				}
			}
		break;
	}
}
function showPublication(id, montre){
	var publi = document.getElementById('titre'+id);
	if(publi){
		if(montre){
			publi.style.display='';
		}else{
			publi.style.display='none';
		}
	}
}
function showProjet(id, statut, montre, e){
	var projet = document.getElementById('projet'+id);
	if(projet){
		if(montre){
			var ok = true;
			var imgProjet = document.getElementById('projet_'+id+'_'+statut).getElementsByTagName('img')[0];
			if(imgProjet){
				if(document.all){
					if(imgProjet.style.filter=='alpha(opacity = 50)'){
						ok = false;
					}
				}else{
					if(imgProjet.style.opacity==0.5){
						ok = false;
					}
				}
			}
			showBulle();
			if(ok){
				projet.style.display='';
			}
		}else{
			projet.style.display='none';
			hideBulle();
		}
	}
}
function triProjet(statut, statutTxt){
	var alpha;
	var projets = document.getElementById('centre').getElementsByTagName('div');
	for(i=0; i<projets.length; i++){
		if(projets[i].className!='clean' && projets[i].className!='marge'){
			var projet = projets[i].id.split('_');
			if(projet[2]==statut){
				alpha = 1;
			}else{
				alpha = 0.5;
			}
			if(document.all){
				projets[i].getElementsByTagName('img')[0].style.filter='alpha(opacity = '+alpha*100+')';
			}else{
				projets[i].getElementsByTagName('img')[0].style.opacity=alpha;
			}
		}
	}
	var statuts = document.getElementById('sousmenu').getElementsByTagName('a');
	for(i=0; i<statuts.length; i++){
		if(statuts[i].id=='statut'+statut){
			statuts[i].className='selected';
		}else{
			statuts[i].className='';
		}
	}
	changeStatut(statutTxt);
}
function changeStatut(statut){
	var req = createXMLHttpRequest();
	req.onreadystatechange = function(){
		if(req.readyState == 4){
			return true;
		}else{
			return false;
		}
	}
	appel="changeStatut.php?statut="+statut;
	req.open("GET",appel,true);
	req.send(null);
}
function masqueProjet(statut){
	var projets = document.getElementById('centre').getElementsByTagName('a');
	for(i=0; i<projets.length; i++){
		var projet = projets[i].id.split('_');
		if(projet[2]==statut){
			projets[i].style.display='block';
		}else{
			projets[i].style.display='none';
		}
	}
	var statuts = document.getElementById('sousmenu').getElementsByTagName('a');
	for(i=0; i<statuts.length; i++){
		if(statuts[i].id=='statut'+statut){
			statuts[i].className='selected';
		}else{
			statuts[i].className='';
		}
	}	
}
function placeBulle(e){
	if(!e){
		e=window.event;
	}
	if (document.layers) {
		xpage = e.pageX;
		ypage = e.pageY;
	} else if (document.all) {
		xpage = e.x;
		ypage = e.y;
	} else if (document.getElementById) {
		xpage = e.clientX;
		ypage = e.clientY;
		if(e.pageX) xpage = e.pageX;
		if(e.pageY) ypage  = e.pageY;
	}
	var availHeight;
	var availWidth;
	var infobulle=document.getElementById('infobulle');
	infobulle.style.left=(xpage+5)+'px';
	infobulle.style.top=(ypage-5-infobulle.offsetHeight)+'px';
	if(typeof(window.innerWidth) == 'number'){
		availHeight = window.innerHeight;
		availWidth = window.innerWidth;
	}else if(document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)){
		availHeight = document.documentElement.clientHeight;
		availWidth = document.documentElement.clientWidth;
	}else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
		availHeight = document.body.clientHeight;
		availWidth = document.body.clientWidth;
	}
	if(xpage+5+infobulle.offsetWidth>availWidth){
		infobulle.style.left=(xpage-5-infobulle.offsetWidth)+'px';
	}
	if(ypage+25+infobulle.offsetHeight>availHeight){
		infobulle.style.top=(ypage-5-infobulle.offsetHeight)+'px';
	}else{
		infobulle.style.top=(ypage+25)+'px';
	}
}
function showBulle(){
	document.getElementById('infobulle').style.display='';
}
function hideBulle(){
	document.getElementById('infobulle').style.display='none';
}