document.onmousemove = mouse_monitor; // attacher un evenement au document entier // B.Rieder
var m_y, m_x;
v_ids = Array("nuage","matrix","voeux","IMP","RFC");
v_matrix = Array("Wake up Neo","","The Matrix has you","","Follow the white rabbit","","Knock, knock Neo");
v_id = "";
v_timeout = new Array();
v_img = 1;
function mouse_monitor(event) { // donne la position du curseur en permanence // B.Rieder
	if(window.event) {									// IE							
    	m_x = window.event.clientX;
    	m_y = window.event.clientY;
  	} else {											// Mozilla
   		m_x = event.clientX;
		m_y = event.clientY;
  	}
	if(window.pageYOffset) {							// corriger la position du curseur selon le scrolling, IE / Autres
		var topoff = window.pageYOffset;
		var topleft = window.pageXOffset;
	} else {
		var topoff = document.body.scrollTop;
		var topleft = document.body.scrollLeft;
	}
	m_y = m_y + topoff;
	m_x = m_x + topleft;
}
function f_affiche(id,xMax,yMax,h) {
	if(h==0) {
		posX = xMax;
		posY = yMax;
	}
	else {
		posX = Math.random()*xMax+12;
		posY = Math.random()*yMax+12;
	}
	$("#"+id).css("left",posX+"px");
	$("#"+id).css("top",posY+"px");
	f_afficherBouton(posX,posY,id);
	$("#fond").fadeIn("slow",function() {
		$("#"+id).fadeIn("slow");
		$("#fermer").fadeIn("slow");
	});
}
function f_typewriter(id, string, pos) {
	var message = "";
	if(pos <= string.length) {
		if(string == "") {
			pos++;
			document.getElementById(id).innerHTML = string;
			v_idTimeout = window.setTimeout("f_typewriter(\""+id+"\",\""+string+"\","+pos+")", 75);
			v_timeout.push(v_idTimeout);
		}
		else {
			for(i=0;i<pos;i++) {
				message += string[i];
			}
			document.getElementById(id).innerHTML = message+"[]";
			pos++;
			v_idTimeout = window.setTimeout("f_typewriter(\""+id+"\",\""+string+"\","+pos+")",75);
			v_timeout.push(v_idTimeout);
		}
	}

}
function f_matrixAffiche(id,nb) {
	if(nb < v_matrix.length) {
		f_typewriter(id,v_matrix[nb],0);
		nb++
		v_idTimeout = window.setTimeout("f_matrixAffiche(\""+id+"\","+nb+")",1500);
		v_timeout.push(v_idTimeout);
	}
	else {
		v_idTimeout = window.setTimeout("f_cache(\""+id+"\")",1500);
		v_timeout.push(v_idTimeout);
	}
}
function f_matrix(id) {
	// Afficher le terminal
	var v_terminal = document.getElementById(id);
	v_terminal.style.top = "12px";
	v_terminal.style.left = "140px";
	f_afficherBouton(140,12,id);
	$("#fond").fadeIn("slow",function() {
		$("#"+id).fadeIn("slow");
		$("#fermer").fadeIn("slow");
	});
	f_matrixAffiche(id,0);
}
function f_nuage(id) {
	f_getTagCloud();
	f_affiche(id,400,200,1);
}
function f_voeux(id) {
	f_affiche(id,55,12,0);
}
function f_cache(id) {
	$("#"+id).fadeOut("slow");
	$("#fermer").fadeOut("slow",function() {
		$("#fond").fadeOut("slow");
	})
}
function f_youtubeAffiche(id,duree) {
	f_affiche(id,300,500,1);
	v_idTimeout = window.setTimeout("f_youtubeCache('"+id+"')", duree*1000);
	v_timeout.push(v_idTimeout);
}
function f_youtubeCache(id) {
	f_cache(id);
}
function f_tourner() {
	document.getElementById("img"+v_img).style.display = "none";
	document.getElementById("span"+v_img).style.display = "none";
	if(v_img == 18) v_img = 1;
	else v_img++;
	document.getElementById("img"+v_img).style.display = "block";
	document.getElementById("span"+v_img).style.display = "block";
}
function f_retourner() {
	document.getElementById("img"+v_img).style.display = "none";
	document.getElementById("span"+v_img).style.display = "none";
	if(v_img == 1) v_img = 18;
	else v_img--;
	document.getElementById("img"+v_img).style.display = "block";
	document.getElementById("span"+v_img).style.display = "block";	
}
function f_afficherBouton(x,y,id) {
	posX = x-12;
	posY = y-12;
	v_id = id;
	$("#fermer").css("top",posY+"px");
	$("#fermer").css("left",posX+"px");
}
function f_afficherInfoBulle(id) {
//	document.getElementById(id).style.display = "block";
	$(".infobulle").hide();
	$("#"+id).slideDown("fast");
}
function f_bougerInfoBulle(id) {
	posX = m_x + 20;
	if(posX < (window.innerWidth - 220)) {
		document.getElementById(id).style.left = (m_x + 20) + "px";
		document.getElementById(id).style.top = (m_y + 20) + "px";
	}
	else {
		document.getElementById(id).style.left = "auto";
		document.getElementById(id).style.right = "10px";
		document.getElementById(id).style.top = (m_y + 20) + "px";
	}
}
function f_cacherInfoBulle(id) {
	$("#"+id).css("display","none");
}
function f_fermer() {
	for(i=0;i<v_timeout.length;i++) {
		window.clearTimeout(v_timeout[i]);
	}
	v_timeout = new Array();
	f_cache(v_id);
}
function f_eco() {
	if(f_styleActif()!="eco") {
		f_activerStyle("eco");
		f_creerCookie("style", "eco", 365);
	}
	else {
		f_activerStyle("main");
		f_creerCookie("style","main", 365);
	}
}
function f_getYoutube() {
	$.ajax({
		url: "config/inc/youtube.inc.php",
		cache: false,
		success: function(html) {
			$("#youtube").html(html);
		}
	});
}
function f_getTagCloud() {
	$.ajax({
		url: "config/inc/tagCloud.inc.php",
		cache: false,
		success: function(html) {
			$("#nuage").html(html);
		}
	});
}