<!--
var Popup =
{
	// main properties
	overlay : 		null,
	box : 			null,
	container : null,
	span_img_index :null,
	displayed : 	false,
	timeout :		null,
	interval : 		null,
	close_str :		'fermer',
	img_close_url :	'close.gif',
	img_loading :	null,
	img_loading_url :'loading.gif',
	display_close :true,

	// Style
	opacity : 		0,
	window_width: 	0,
	window_height: 	0,
	window_y : 		0,

	// Album
	autocheck_images:true,
	interval_img: 	null,
	img_tmp	:		null,
	img_index	:	-1,
	album : 		new Array(),
	album_id : 		-1,

	// Slideshow
	slideshow :		false,
	slideshow_sec :	3,
	interval_slideshow:null,


	// initialisation
	init: function()
	{
		if (window.oper || (!window.addEventListener && !window.attachEvent)) { return; }

		this.addEvent(window, 'load', this.init_load);
		this.addEvent(window, 'resize', this.redim_image);
		this.addEvent(window.document, 'mousewheel', this.wheel);
		this.addEvent(window.document, 'keyup', this.display_image_keyup);
	},
	addEvent: function(o, e, f)
	{
			if (window.addEventListener) { o.addEventListener(e, f, false); return true; }
			if (window.attachEvent) return o.attachEvent('on' + e, f);
			return false;
	},
	init_load: function()
	{
		// Creation OVERLAY
		Popup.overlay = document.createElement('div');
		Popup.overlay.id = 'popup_overlay';
		document.body.appendChild(Popup.overlay);

		// Creation BOX
		Popup.box = document.createElement('div');
		Popup.box.id = 'popup_box';
		// -- header
		var el = document.createElement('div');
		el.id = 'popup_box_header';

		if(Popup.display_close)
		{
			var a = document.createElement('a');
			a.id = 'popup_box_close';
			if(Popup.close_str != '')
				a.innerHTML = Popup.close_str;
			a.href = '#';
			a.onclick = function()
			{
				Popup.hide();
			};
			var img = document.createElement('img');
			img.src = Popup.img_close_url;
			img.align = 'absmiddle';
			a.appendChild(img);
			el.appendChild(a);
		}

		Popup.box.appendChild(el);

		// -- img container
		Popup.container = document.createElement('div');
		Popup.container.id = 'popup_box_container';
		Popup.box.appendChild(Popup.container);

		// -- footer
		el = document.createElement('div');
		el.id = 'popup_box_footer';
		Popup.span_img_index = document.createElement('span');
		Popup.span_img_index.id = 'popup_box_index';
		el.appendChild(Popup.span_img_index);
		Popup.box.appendChild(el);
		document.body.appendChild(Popup.box);

		var reg = new RegExp("(.?)popupcss\\[(\\d+)\\](.?)", "g");
		var album_id_tmp = null;
		for(var i = 0; i < document.images.length ; i++)
		{
			if(reg.test(document.images[i].className))
			{
				var album_id_tmp = document.images[i].className.replace(reg, '$2');
				if(album_id_tmp >= 0)
				{
					if(!Popup.album[album_id_tmp])
						Popup.album[album_id_tmp] = new Array();
					document.images[i].album_id = album_id_tmp;
					document.images[i].popup_id = Popup.album[album_id_tmp].length;
					document.images[i].parentNode.onclick = function()
					{
						Popup.display_album(this.firstChild.album_id, this.firstChild.popup_id);
						return false;
					}
					if(Popup.autocheck_images)
						Popup.album[album_id_tmp].push(document.images[i].src);
				}
			}
		}
	},
	// get DOM
	get_element : function(id)
	{
		if(document.all)
		{
			return document.all[id];
		}
		else if (document.getElementById)
		{
			return document.getElementById(id);
		}
		else if(document.layers)
		{
			return document.layers[id];
		}
		return null;
	},

	// display
	display: function(message)
	{
		if(typeof message != 'undefined')
		{
			this.container.innerHTML = message;
		}
		this.overlay.style.display = 'block';
		this.box.style.display = 'none';
		this.opacity = 0;
		for(var i = 0; i < 11; i++)
			this.timeout = setTimeout('Popup.set_opacity("+")',50*i);
    	this.interval = setInterval('Popup.center()', 10);
		this.displayed = true;
		document.body.style.overflow = 'hidden';
	},

	// hide
	hide: function()
	{
		Popup.opacity = 11;
		for(var i = 11; i > 0; i--)
			Popup.timeout = setTimeout('Popup.set_opacity("-")',50*i);
		clearInterval(Popup.interval);
		Popup.img_index = -1;
		Popup.displayed = false;
	},

	// apparition fade in/out
	set_opacity: function(direction)
	{
		this.opacity = (direction == '+') ? this.opacity + 1 : this.opacity - 1;
		this.box.style.opacity = this.opacity/10;
		this.box.style.filter = 'alpha(opacity=' + this.opacity*10 + ')';
		if(direction == '+' && this.opacity == 11)
		{
			this.box.style.display = 'block';
			this.span_img_index.style.display = 'block';
		}
		else if(direction == '-' && this.opacity <= 0)
		{
			this.overlay.style.display = 'none';
			this.box.style.display = 'none';
			this.span_img_index.style.display = 'none';
			document.body.style.overflow = 'auto';
		}
		clearTimeout(this.timeout);
	},

	// assigne les valeur des dimensions de la fenêtre
	get_dimensions : function()
	{
	    if ( typeof( window.innerWidth ) == 'number' ){
	        this.window_width  = 	window.innerWidth;
	        this.window_height = 	window.innerHeight;
	    }else if ( document.documentElement &&
	             ( document.documentElement.clientWidth ||
	               document.documentElement.clientHeight ) ){
	        this.window_width  = 	document.documentElement.clientWidth;
	        this.window_height = 	document.documentElement.clientHeight;
	    }
	    else if ( document.body &&
	            ( document.body.clientWidth || document.body.clientHeight ) ){
	        this.window_width  = 	document.body.clientWidth;
	        this.window_height = 	document.body.clientHeight;
	    }

		if ( document.documentElement && document.documentElement.scrollTop ){
	        this.window_y = 		document.documentElement.scrollTop;
	    }else if ( document.body && document.body.scrollTop ){
	        this.window_y = 		document.body.scrollTop;
	    }else if ( window.pageYOffset ){
	        this.window_y = 		window.pageYOffset;
	    }else if ( window.scrollY ){
	        this.window_y = 		window.scrollY;
	    }
	},

	// Centre la BOX
	center: function()
	{
		if(this.displayed)
		{
			this.get_dimensions();
			// overlay
			this.overlay.style.width = 	this.window_width + "px";
			this.overlay.style.height= 	this.window_height + this.window_y +"px";
			// box
		    this.box.style.position = 	'absolute';
		    this.box.style.zIndex   = 	99;
			this.box.style.display  = 	'block';
		    this.box.style.left = 		(( this.window_width  - this.box.offsetWidth  ) / 2) + 'px';
		    this.box.style.top  = 		(( this.window_height - this.box.offsetHeight ) / 2 + this.window_y) + 'px';
		    if(parseInt(this.box.style.top) <= 15)
		    	this.box.style.top = '15px';
		}
	},

	// Déplacement roulette souris
	wheel: function(event)
	{
		try{
			var delta = 0;
			if (!event) event = window.event;
			if (event.wheelDelta) {
				delta = event.wheelDelta/120;
				if (window.opera) delta = -delta;
			} else if (event.detail) {
				delta = -event.detail/3;
			}
			if (delta)
				this.center();
		}catch(e)
		{

		}

	},

	// init display album
	display_album: function(album_id, img_id)
	{
		this.display();
		// Append loading image
		this.img_loading = new Image();
		this.img_loading.src= this.img_loading_url;
		this.img_loading.style.position = 'absolute';

		this.box.appendChild(this.img_loading);
		if(album_id == undefined)
			album_id = 0;
		this.album_id = album_id;
		this.display_image(img_id);

		if(this.slideshow == true)
		{
			this.interval_slideshow = setInterval('Popup.display_image()', this.slideshow_sec * 1000);
		}
	},

	// Action sur les touches
	display_image_keyup : function(e)
	{
		if(Popup.displayed)
		{
			if (!e) e= event;

			var keycode = 0;
			if(e.charCode)
				keycode = e.charCode;
			else if(e.which)
				keycode = e.which;
			else if(e.keyCode)
				keycode = e.keyCode;

			if(keycode == 37) // left
				Popup.display_image(Popup.img_index -1);
			else if(keycode == 38) // up
				Popup.display_image(0);
			else if(keycode == 39) // right
				Popup.display_image(Popup.img_index + 1);
			else if(keycode == 40) // down
				Popup.display_image(Popup.album[Popup.album_id].length -1);
			else if(Popup.display_close == true && keycode == 27) // ESC
				Popup.hide();
			else if(keycode == 32) // SPACE
			{
				if(Popup.interval_slideshow && Popup.interval_slideshow > 0)
				{
					clearInterval(Popup.interval_slideshow);
					Popup.interval_slideshow = 0;
				}
				else
					Popup.interval_slideshow = setInterval('Popup.display_image()', Popup.slideshow_sec * 1000);
			}
		}
	},

	// for each image
	display_image: function(index)
	{
		if(Popup.displayed)
		{
			this.center();
			this.span_img_index.style.display = 'none';
			this.img_tmp = new Image();
			if(this.album[this.album_id].length > 0)
			{
				if(index == undefined)
					index = this.img_index + 1;
				if(index < 0)
					index = this.album[this.album_id].length - 1;
				else if(index >= this.album[this.album_id].length)
					index = 0;

				this.img_index = index;
				this.img_tmp.src = this.album[this.album_id][this.img_index];
				this.img_tmp.style.cursor = 'pointer';
				this.img_tmp.onclick = function()
				{
					Popup.display_image()
				}
				// pagination
				this.span_img_index.innerHTML = ((this.img_index + 1) + ' / ' + this.album[this.album_id].length);
			}

			// Remove Last Img
			if(this.container.childNodes.length > 0)
				this.container.removeChild(this.container.lastChild);


			this.img_loading.style.display = 'block';
			this.img_loading.style.left = 	((parseInt(this.box.offsetWidth) - this.img_loading.width) / 2)  + 'px';
			this.img_loading.style.top = 	(parseInt(this.box.offsetHeight) / 2) + 'px';

			clearInterval(this.interval_img);
			this.interval_img = setInterval('Popup.adapt_image()', 100);
		}
	},

	// Affichage de l'image une fois qu'elle est chargée
	adapt_image:function()
	{
		if(this.img_tmp.complete)
		{
			clearInterval(this.interval_img);
			if(this.interval_slideshow == true)
			{
				Popup.interval_slideshow = setInterval('Popup.display_image()', Popup.slideshow_sec * 1000);
			}
			this.redim_image();
			this.img_loading.style.display = 'none';
			this.container.appendChild(this.img_tmp);
			this.span_img_index.style.display = 'block';
			this.center();
		}
		else
		{
			if(this.interval_slideshow == true)
			{
				clearInterval(this.interval_slideshow);
			}
		}
	},

	// sert pour Popup.adapt_image et document.onresize (Popup.init)
	redim_image:function()
	{
		if(Popup.displayed && Popup.img_tmp && Popup.img_tmp.complete)
		{
			Popup.get_dimensions();

			// Conserver les dimensions d'origine de l'image (nécessaire pour le resize)
			if(!Popup.img_tmp.first_width)
			{
				Popup.img_tmp.first_width = Popup.img_tmp.width;
				Popup.img_tmp.first_height = Popup.img_tmp.height;
			}
			else
			{
				Popup.img_tmp.width = Popup.img_tmp.first_width;
				Popup.img_tmp.height = Popup.img_tmp.first_height;
			}

			var w_space = 15;
			var h_space = 50;
			while(Popup.img_tmp.width + w_space> Popup.window_width || Popup.img_tmp.height + h_space > Popup.window_height)
			{
				Popup.img_tmp.width -= Math.floor(Popup.img_tmp.width / 10);
				Popup.img_tmp.height -= Math.floor(Popup.img_tmp.height / 10);
			}

			Popup.box.style.width = (Popup.img_tmp.width + w_space)+ 'px';
			Popup.box.style.height = (Popup.img_tmp.height + h_space) + 'px';

			Popup.center();
		}
	}
}
-->
