/*
 * MESSAGE STYLE FACEBOOK v1.0.1
 * -----------------------------
 * © Point Communication
 */

var image = new Array(
			"../images/ico/0.png", 
			"../images/ico/1.png", 
			"../images/ico/2.png");

var timer_close 	= "6000";
var timer_opacity 	= "250";		
var timer_out 		= null; 


function lightbox(statut, message) {
	
	// Récupère les éléments dans le div contenu
	document.getElementById('lightbox_txt').innerHTML = message;	
	document.getElementById('lightbox').style.backgroundImage = "url("+image[statut]+")";	
	
	// Stop la fermeture automatique
	if (timer_out != null) clearTimeout(timer_out);

	// Détermine le style d'affichage
	style(statut);
			
	// Affiche le message
	lightbox_open('lightbox');
	
}


function lightbox_open(id) {
	
	var objet = document.getElementById(id);
		
	if (objet) {

		// Déclenche l'ouverture (passe de 0 à 100)
		opacity_box(id, 0, 100, timer_opacity);
		
		// Déclenche une fermeture automatique
		timer_out = setTimeout("lightbox_close('"+objet.id+"')", timer_close);
		
	}	
	
	
}


function lightbox_close(id) {

	// Masque le message (passe de 100 à 0)
	opacity_box(id, 100, 0, timer_opacity);
		
	// Stop la fermeture automatique
	clearTimeout(timer_out);
	
	// Variable par défaut
	timer_out = null;
	
}


function opacity_box(id, opacStart, opacEnd, millisec){

	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	if (opacStart > opacEnd) {

		for (i = opacStart; i >= opacEnd; i--) {
			setTimeout("change_opacity(" + i + ",'" + id + "')", (timer * speed));
			timer++;
		}
		
	}else{
	
		if (opacStart < opacEnd) {
			
			for (i = opacStart; i <= opacEnd; i++) {
				setTimeout("change_opacity(" + i + ",'" + id + "')", (timer * speed));
				timer++;
			}
			
		}
		
	}
			
}


function change_opacity(opacity, id) {
 
    var object = document.getElementById(id).style;
 
    object.opacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
		
}	


function init() {
	
	if (timer_out == null) {
		
		document.getElementById('lightbox').style.opacity = 0;
		document.getElementById('lightbox').style.filter = "alpha(opacity=0)";
		
	}
	
}


function style(statut) {
	
	var objet = document.getElementById('lightbox');
	
	switch (statut) {
		
		// Erreur
		case 0:
		objet.style.backgroundColor = '#FFE2E0';
		objet.style.border = '1px solid #D2BBB9';					
		break;

		// Succés
		case 1:
		objet.style.backgroundColor = '#DDFFDB';
		objet.style.border = '1px solid #AADBBC';				
		break;

		// Infos
		case 2:
		objet.style.backgroundColor = '#FFFFE1';
		objet.style.border = '1px solid #C8C8B0';			
		break;
		
	}
	
}


// ECRITURE DU CSS DANS LA PAGE //
document.write('<style type="text/css">');
			
	document.write('#lightbox {');
	document.write('	position: fixed;');
	document.write('	bottom: 10px;');
	document.write('	left: 10px;');
	document.write('	padding: 5px;');
	document.write('    background: no-repeat 3px 3px;');
	document.write('	cursor: pointer;');
	document.write('	z-index: 1000;');
	document.write('}');

	document.write('#lightbox #lightbox_txt {');
	document.write('	font: 11px Verdana;');
	document.write('	margin: 0;');
	document.write('	padding: 0;');
	document.write('	margin-left: 16px;');	
	document.write('	color: #000;');
	document.write('}');
			
document.write('</style>');


// AFFICHE LE DIV DANS LA PAGE //
document.write('<div id="lightbox" onclick="lightbox_close(this.id)"><div id="lightbox_txt"></div></div>');


// Masque le div au chargement
window.onload = init;

