width=100;
height=1;
preload_image_object = new Image();

function init(){
	var MonTableau = document.getElementsByTagName('img');
	i=0;
	while(i<MonTableau.length){
		num=MonTableau[i].src.indexOf("/e.png");
		if(num<0){
			MonTableau[i].onclick=function(){popup(this);}
			MonTableau[i].style.cursor="pointer";
		}
		i++;
	}
	
}
function popup(objet){
		preload_image_object.src=objet.src;
		var fond=document.createElement("div");
		fond.className="cache";
		fond.id="fond";
		fond.style.top='0px';
		fond.style.left='0px';
		fond.style.width=screen.width+'px';
		fond.style.height=screen.height+'px';
		fond.onclick=function(){
			exit_popup();
			}
		document.body.appendChild(fond);

		var popup=document.createElement("div");
		popup.className="popup";
		popup.id="popup";
		popup.onclick=function(){
			exit_popup();
			}
		popup.style.top=(screen.height/2)-110+"px";
		popup.style.left=(screen.width/2)-(width/2)+"px";
		document.body.appendChild(popup);
		size2();
}

function size(){
	document.getElementById('popup').style.left=(screen.width/2)-(width/2)+"px";
	document.getElementById('popup').style.width=width+"px";
		width+=80;
		if(width<700){
			time2=setTimeout("size()",1);
		}else{
			clearTimeout(time2);
			document.getElementById('popup').style.width=width+"px";
			
			img_w=preload_image_object.width;
			img_h=preload_image_object.height;
			param="height=500px";
			if(img_w>img_h){param="width=700px";}else{param="height=500px";}
			document.getElementById('popup').innerHTML="<img id='apercu' src='"+preload_image_object.src+"' "+param+" />";
			if(document.getElementById('apercu').height>500){document.getElementById('apercu').height="500";}
			if(document.getElementById('apercu').width>700){document.getElementById('apercu').width="700";}
		}
}

function size2(){
	document.getElementById('popup').style.top=(screen.height/2)-(height/2)-110+"px";
	document.getElementById('popup').style.height=height+"px";
		height+=30;
		if(height<500){
			time2=setTimeout("size2()",1);
		}else{
			clearTimeout(time2);
			document.getElementById('popup').style.height=height+"px";
			size();
		}
}
function exit_popup(){
	document.getElementById('popup').innerHTML="";
	document.body.removeChild(document.getElementById('popup'));
	document.body.removeChild(document.getElementById('fond'));
	width=100;
	height=1;
}
