/*
La fonction decorer() se charge d'organiser la suite de fonctions utilisées pour la page d'accueil.
*/

function decorer() {
	deco_violet();
	setTimeout("hide()",1000);
	setTimeout("deco_bleu1()",2000);
	setTimeout("hide()",3000);
	setTimeout("deco_orange()",4000);
	setTimeout("hide()",5000);
	setTimeout("deco_bleu2()",6000);
	setTimeout("hide()",7000);
}



/*
La fonction setOpacity() permet de choisir l'opacité avec laquelle une balise est.
*/

function setOpacity(obj,xOpacity){
	obj.style.opacity = xOpacity;
	obj.style.MozOpacity = xOpacity;
	obj.style.KHTMLOpacity = xOpacity;
	obj.style.filter = 'alpha(opacity=' + (xOpacity*100) + ')';
}



/*
La fonction getOpacity permet de récupérer l'opacité actuelle d'un élément.
*/

function getOpacity(obj){
	if(obj.style.opacity)
		return parseFloat(obj.style.opacity);
	if(obj.style.MozOpacity)
		return parseFloat(obj.style.MozOpacity);
	if(obj.style.KHTMLOpacity)
		return parseFloat(obj.style.KHTMLOpacity);
	if(obj.style.filter){
		var chaine = obj.style.filter;
		var opacite = chaine.charAt(14); //On récupère la valeur alpha(opacity=XXX)
		if(chaine.charAt(15)!=")")
			opacite += chaine.charAt(15);
		if(chaine.charAt(16)!=")")
			opacite += chaine.charAt(16);
		return parseFloat(opacite);
	}
}



/*
Cette fonction sert à appliquer un effet de flou sur l'apparition et la disparition d'un élément.
Pendant les 500 premières millisecondes, l'image va gagner en opacité, puis retomber à 0 les 500ms suivantes.
*/

function afficher_progr(elt,time){
	if(time<500)
		fadeIn(elt);
	if(time>=500)
		fadeOut(elt);
	if(time>=1000)
		return;
	setTimeout(
		function(){afficher_progr(elt,time+100);}
		,100); //Toutes les 100ms, on relance la fonction en prenant note du temps écoulé
}


function fadeIn(elt){
	var opacite = getOpacity(elt);
	opacite += 0.2;
	setOpacity(elt,opacite);
}

function fadeOut(elt){
	var opacite = getOpacity(elt);
	opacite -= 0.2;
	setOpacity(elt,opacite);
}


/*
Toutes les fonctions de décoration ci dessous ne diffèrent que par l'image appelée.
*/

function deco_violet() {
	var theRules=new Array();
	if(document.styleSheets[0].cssRules){
		theRules=document.styleSheets[0].cssRules;
		theRules[1].style.setProperty('margin-left','150px',null);
		theRules[1].style.setProperty('margin-top','170px',null);
	}
	else if(document.styleSheets[0].rules){
		theRules=document.styleSheets[0].rules;
		theRules[1].style.marginLeft = '150px';
		theRules[1].style.marginTop = '170px';
	}
	else return;
	var elt;
	elt=document.getElementById('deco');
	elt.innerHTML='<img src="IMG/gif/pap_violet_transparent.gif"></img>';
	setOpacity(elt,0); //On fixe d'abord l'opacité à O.
	afficher_progr(elt,0); // Puis on va l'augmenter progressivement.
}

	
function deco_bleu1() {
	var theRules=new Array();
	if(document.styleSheets[0].cssRules){
		theRules=document.styleSheets[0].cssRules;
		theRules[1].style.setProperty('margin-left','200px',null);
		theRules[1].style.setProperty('margin-top','110px',null);
	}
	else if(document.styleSheets[0].rules){
		theRules=document.styleSheets[0].rules;
		theRules[1].style.marginLeft = '200px';
		theRules[1].style.marginTop = '110px';
	}
	var elt;
	elt=document.getElementById('deco');
	elt.innerHTML='<img src="IMG/gif/pap_bleu1_transparent.gif"></img>';
	setOpacity(elt,0); //On fixe d'abord l'opacité à O.
	afficher_progr(elt,0); // Puis on va l'augmenter progressivement.
}


function deco_bleu2() {
	var theRules=new Array();
	if(document.styleSheets[0].cssRules){
		theRules=document.styleSheets[0].cssRules;
		theRules[1].style.setProperty('margin-left','400px',null);
		theRules[1].style.setProperty('margin-top','100px',null);
	}	
	else if(document.styleSheets[0].rules){
		theRules=document.styleSheets[0].rules;
		theRules[1].style.marginLeft = '400px';
		theRules[1].style.marginTop = '100px';
	}
	var elt;
	elt=document.getElementById('deco');
	elt.innerHTML='<img src="IMG/gif/pap_bleu2_transparent.gif"></img>';
	setOpacity(elt,0); //On fixe d'abord l'opacité à O.
	afficher_progr(elt,0); // Puis on va l'augmenter progressivement.
}


function deco_orange() {
	var theRules=new Array();
	if(document.styleSheets[0].cssRules){
		theRules=document.styleSheets[0].cssRules;
		theRules[1].style.setProperty('margin-left','300px',null);
		theRules[1].style.setProperty('margin-top','60px',null);
	}
	else if(document.styleSheets[0].rules){
		theRules=document.styleSheets[0].rules;
		theRules[1].style.marginLeft = '300px';
		theRules[1].style.paddignTop = '60px';
	}	
	var elt;
	elt=document.getElementById('deco');
	elt.innerHTML='<img src="IMG/gif/pap_orange_transparent.gif"></img>';
	setOpacity(elt,0); //On fixe d'abord l'opacité à O.
	afficher_progr(elt,0); // Puis on va l'augmenter progressivement.
}


/*
La fonction hide() supprime le contenu d'une div.
*/

function hide() {
	var theRules=new Array();
	if(document.styleSheets[0].cssRules){
		theRules=document.styleSheets[0].cssRules;
		theRules[1].style.setProperty('margin-top','140px',null);
		theRules[1].style.setProperty('margin-left','90px',null);
	}
	else if(document.styleSheets[0].rules){
		theRules=document.styleSheets[0].rules;
		theRules[1].style.marginTop = '140px'
		theRules[1].style.marginLeft = '90px'
	}
	var elt;
	elt=document.getElementById('deco');
	elt.innerHTML="";
}