/**
 * Javascripts de la Lightbox.
 * @author David LIMA
 * @date 21/09/2008
 * @lastupdate 21/09/2008
 *
 * @copyright LBA Thivel
 */

/*
 * Fonction qui établi le contenu de la lightbox depuis un composant HTML.
 * @param String head: titre du lightbox
 * @param Object value: composant HTML
 */
function lightboxAppendContent(head, value) {
	var lightbox_header  = document.getElementById('lightbox_header');
	var lightbox_content = document.getElementById('lightbox_content');
	lightbox_header.innerHTML = head;
	lightbox_content.appendChild(value);
}

/*
 * Affiche la lightbox.
 */
function lightboxDisplay() {
	var backbox  = document.getElementById('backbox');
	var lightbox = document.getElementById('lightbox');
	backbox.style.display  = 'block';
	lightbox.style.display = 'block';
	lightboxAdjustSize();
}

/*
 * Masque la lightbox.
 */
function lightboxClose() {
	var backbox  = document.getElementById('backbox');
	var lightbox = document.getElementById('lightbox');
	var lightbox_content = document.getElementById('lightbox_content');
	var nodes = lightbox_content.childNodes;
        for (var i = 1; i <= nodes.length; i++) {
		lightbox_content.removeChild(nodes[i]);
	}
	backbox.style.display  = 'none';
	lightbox.style.display = 'none';
}

/*
 * Ajuste la taille du lightbox à son contenu et le centre sur la page.
 */
function lightboxAdjustSize() {
	var lightbox = document.getElementById('lightbox');
	var lightbox_content = document.getElementById('lightbox_content');
	var w = lightbox.offsetWidth;
	var h = lightbox.offsetHeight;
	var pagew = window.innerWidth;
	var pageh = window.innerHeight;
	if (!pagew || !pageh) {
		var pagew = document.body.clientWidth;
		var pageh = document.body.clientHeight;
	}
	lightbox.style.top  = ((parseInt(pageh) - parseInt(h)) / 2) + 'px';
	lightbox.style.left = ((parseInt(pagew) - parseInt(w)) / 2) + 'px';
}