/*************************************************/
/* Script javascript www.progmatique.fr          */
/* Simon M                                       */
/*************************************************/

function addListener(func,action)
{
    if (window.addEventListener)
	{
         window.addEventListener(action, func, false);
    }
	else if (document.addEventListener)
	{
         document.addEventListener(action, func, false);
    }
	else if (window.attachEvent)
	{
         document.attachEvent("on"+action, func);
    }
}

var hahaNbDiv = 0;
function hahaDiv(hahasX, hahasY, x, y)
{
	hahaNbDiv+=1;
	if(hahaNbDiv==100)
		hahaNbDiv=0;
	
	if(document.getElementById("s"+hahaNbDiv)==null)
		document.getElementById("footer").innerHTML=document.getElementById("footer").innerHTML+"<div id=\"s"+hahaNbDiv+"\"></div>";
	
	document.getElementById("s"+hahaNbDiv).style.width="5px";
	document.getElementById("s"+hahaNbDiv).style.height="5px";
	var coul1=(hahasX%9);
	var coul2=(hahasY%9);
	var coul3=(hahasY+hahasX)%9;

	document.getElementById("s"+hahaNbDiv).style.backgroundColor="#"+coul1+""+coul2+""+coul3+""+coul1+""+coul2+""+coul3;
	document.getElementById("s"+hahaNbDiv).style.position="absolute";
	document.getElementById("s"+hahaNbDiv).style.left=hahasX+x+"px";
	document.getElementById("s"+hahaNbDiv).style.top=hahasY+y+"px";
}

function hahaClick(e)
{
	var hahasX,hahasY;
	if(!window.event)
	{
		hahasX	=	e.pageX;
		hahasY	=	e.pageY;
	}
	else
	{
		hahasX	=	window.event.clientX;
		hahasY	=	window.event.clientY;
		var doc;
		if( document.documentElement && document.documentElement.clientWidth)
			doc	=	document.documentElement;
		else
			doc	=	document.body;

		hahasX	+=	doc.scrollLeft;
		hahasY	+=	doc.scrollTop;
	}
	hahaDiv(hahasX,hahasY,20,0);
	hahaDiv(hahasX,hahasY,-20,0);
	hahaDiv(hahasX,hahasY,0,20);
	hahaDiv(hahasX,hahasY,0,-20);
}

function dessin()
{
	addListener(hahaClick, "mousemove");
}

/* C'est quoi ca? :) */
var keys = new Array();
var code = "38,38,40,40,37,39,37,39,66,65";

function haha(e)
{
	var e = (typeof e != "undefined") ? e : window.event; 
	keys.push(e.keyCode);
	if (keys.toString().indexOf(code) >= 0)
	{
		dessin();
		keys = [];
	}
}

addListener(haha, "keydown");

/* FADE */
function Opacite(id,opa) { 
    var objet = document.getElementById(id);
	if(objet!=null)
	{
		objet.style.opacity = (opa / 100); 
		objet.style.MozOpacity = (opa / 100); 
		objet.style.KhtmlOpacity = (opa / 100); 
		objet.style.filter = "alpha(opacity=" + opa + ")"; 
	}
}

function FadeLivre(opac,type){
	Opacite("showlivre",opac);
	var e1 = document.getElementById("showlivre"); 
	if(e1!=null)
	{
		if(type){
			if(opac>10)
				setTimeout("FadeLivre("+(opac-10)+",true)",40);
			else
				e1.style.display="none";
		}
		else{
			if(e1.style.display=="none")
				e1.style.display="block";
			if(opac<90)
				setTimeout("FadeLivre("+(opac+10)+",false)",40);
			else
				Opacite("showlivre", 100);
		}
	}
}

function switchLiv()
{
	var el = document.getElementById("showlivre");
	var e2 = document.getElementById("msglivre");
	if((el!=null)&(e2!=null))
	{
		if(el.style.display != "none")
		{
			FadeLivre(90,true);
			e2.innerHTML="Afficher le livre d'or";
		}
		else
		{
			FadeLivre(10,false);
			e2.innerHTML="Cacher le livre d'or";
		}
	}
}

