function MouseEvent(e) {
	// Construction d'un objet e standard contenant en plus les informations suivantes sur le mouse event comme propriétés : target (élément au dessus duquel a eu lieu l'event), elementXpos et elementYpos (position du curseur par rapport à l'élément au dessus duquel a eu lieu l'event), documentXpos et documentYpos (poisition du curseur par rapport au document)

	// ATTENTION : l'élément auquel est attaché l'événement doit être stylisé en { position: relative } pour que documentXpos soit évalué correctement dans Mozilla !
	
	if (!e) var e = window.event;

	if (e.target) this.target = e.target;
	else if (e.srcElement) this.target = e.srcElement;
	if (this.target.nodeType == 3) this.target = this.target.parentNode; // defeat Safari bug
	
	if (e.pageX) 	{
		this.documentXpos = e.pageX;
		this.documentYpos = e.pageY;
	}
	else if (e.clientX) 	{
		this.documentXpos = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		this.documentYpos = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}	// posx and posy contain the mouse position relative to the document

	if(e.layerX) {
		this.elementXpos = e.layerX;
		this.elementYpos = e.layerY;
	}
	else if(e.offsetX) {
		this.elementXpos = e.offsetX;
		this.elementYpos = e.offsetY;
	}
}

enlarge_timeout = new Array();

function format_caption(caption) {
	caption = caption.replace(RegExp("''([^']+)''", "g"), "<i>$1</i>");
	temp = caption.split(/\|\|/g);
	if(temp.length > 1) {
		caption = '<div style="padding-top: 4px; font-weight: bold;">' + temp[0] + '</div>' + temp[1];
	}
	caption = caption.replace(/\|/g, "<br />");
	return caption;
}

function enlargeImage(width, height, direction, e) {
	e = new MouseEvent(e);
	if (e.elementXpos) {
		if (!document.getElementById('enlarged_image')) {
			enlarged_image = document.createElement('img');
			enlarged_image.setAttribute('id', 'enlarged_image');
			enlarged_image.setAttribute('style', 'position: absolute; visibility: hidden;');
			enlarged_image.onmouseout = hideEnlargedImage;
			document.body.appendChild(enlarged_image);

			enlarged_image_caption = document.createElement('div');
			enlarged_image_caption.setAttribute('id', 'enlarged_image_caption');
			enlarged_image_caption.setAttribute('style', 'position: absolute; visibility: hidden; background-color: #F9E3A9; padding: 2px; font: 10px Verdana, sans-serif;');
			enlarged_image_caption.onmouseout = hideEnlargedImage;
			document.body.appendChild(enlarged_image_caption);
		}
		else {
			hideEnlargedImage();
			enlarged_image = document.getElementById('enlarged_image');
			enlarged_image_caption = document.getElementById('enlarged_image_caption');
		}

		temp_left = (e.documentXpos - e.elementXpos);
		end_left = temp_left - ((direction == "left")?width - e.target.width:0);
		temp_width = e.target.width;
		temp_height = e.target.height;
		horizontal_step = Math.round((width - e.target.width) / 5);
		vertical_step = Math.round((height - e.target.height) / 5);
		horizontal_offset = (direction == "left") ? horizontal_step : 0;
		delay = 0;

		enlarged_image.style.left = temp_left + "px";
		enlarged_image.style.top = (e.documentYpos - e.elementYpos) + "px";
		enlarged_image.src = e.target.src;
		if (e.target.parentNode.href) {
			enlarged_image.style.cursor = "pointer";
			eval("enlarged_image.onmousedown = function () { window.location = '" + e.target.parentNode.href + "'; };");
		}
		enlarged_image.width = temp_width;
		enlarged_image.height = temp_height;
		enlarged_image.style.visibility = "visible";

		enlarged_image_caption.innerHTML = format_caption(e.target.alt);
		enlarged_image_caption.style.width = (width - 4) + 'px';
		enlarged_image_caption.style.top = (e.documentYpos - e.elementYpos + height) + 'px';
		enlarged_image_caption.style.left = end_left + 'px';

		for (a=0; a<4 ; a++) {
			temp_left -= horizontal_offset;
			temp_width += horizontal_step;
			temp_height += vertical_step;
			delay += 40;
			enlarge_timeout[a] = setTimeout("document.getElementById('enlarged_image').style.left = '" + temp_left + "px'; document.getElementById('enlarged_image').width = '" + temp_width + "'; document.getElementById('enlarged_image').height = '" + temp_height + "';", delay);
		}
		enlarge_timeout[4] = setTimeout("document.getElementById('enlarged_image').style.left = '" + end_left + "px'; document.getElementById('enlarged_image').width = '" + width + "'; document.getElementById('enlarged_image').height = '" + height + "';document.getElementById('enlarged_image').style.visibility='visible'; document.getElementById('enlarged_image_caption').style.visibility='visible';", delay);
	}
}

function hideEnlargedImage() {
	for (a=0; a<5 ; a++) {
		clearTimeout(enlarge_timeout[a]);
	}
	enlarged_image = document.getElementById('enlarged_image');
	enlarged_image.setAttribute('style', 'position: absolute; visibility: hidden;');
	enlarged_image.style.visibility = "hidden";
	enlarged_image.style.left = "0px";
	enlarged_image.style.top = "0px";
	enlarged_image.src = "images/void.gif";
	enlarged_image.width = 1;
	enlarged_image.height = 1;
	enlarged_image.style.cursor = "auto";
	enlarged_image.onmousedown = null;

	enlarged_image_caption = document.getElementById('enlarged_image_caption');
	enlarged_image_caption.style.visibility = "hidden";
	enlarged_image_caption.style.left = "0px";
	enlarged_image_caption.style.top = "0px";
	enlarged_image_caption.src = "images/void.gif";
	enlarged_image_caption.width = 1;
	enlarged_image_caption.height = 1;
	enlarged_image_caption.style.cursor = "auto";
	enlarged_image_caption.onmousedown = null;
}

