var ie=document.all
var ns6=document.getElementById&&!document.all

var reduction = 1	/* indique si l'image est réduite ou non */

/*
 * Affiche une popup pour une oeuvre
 * 
 * description : descriptiond de l'oeuvre
 * image	   : image de l'oeuvre
 * e		   : event
 * h		   : hauteur de l'image 
 * w		   : largeur de l'image
 * ida		   : id de l'artiste
 *
 */
function awPopup(description, image, e, h, w, ida){

	if (document.all|| (document.getElementById&&!document.all) ){

        reduction = 1; // réduction auto.

		/*
		 * reduction automatique en fonction de la résolution ou de la taille de l'image
		 */
		if(reduction==0){
			if(h>screen.height || w>screen.width) {reduction=1}
			else if(screen.width==640 && screen.height==480) {reduction=1}
			else if(screen.width==800 && screen.height==600) {reduction=1}
			else if(screen.width==1024 && screen.height==768) {reduction=1}
			else if(screen.width>1024 && screen.height>768) {reduction=1}
			else {reduction=1} // dans le doute...
		}
		
		/*
		 * mini-images pour changer la taille
		 */
		var img_out = "./inter/images/icon/zoom_out.gif"
		var img_in = "./inter/images/icon/zoom_in_nb.gif"
		if(reduction==1){
			img_out = "./inter/images/icon/zoom_out_nb.gif"
			img_in = "./inter/images/icon/zoom_in.gif"
		}
		
		/*
		 * div du contenu
		 */
		crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
		
		/*
		 * dimension de l'image ( réduite ou pas )
		 */
		imgwidth = w
		imgheight = h
		if(reduction==1){
			imgwidth = w/2
			imgheight = h/2
		}
		
		/*
		 * position dans la page
		 */
		var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
		var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
		pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
		horzpos=ns6? (pageXOffset+window.innerWidth/2-imgwidth/2) : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
		vertpos=ns6? (pgyoffset+window.innerHeight/2-imgheight/2)-70 : (pgyoffset+ietruebody().clientHeight/2-imgheight/2)-70
		if (window.opera && window.innerHeight) vertpos=pgyoffset+window.innerHeight/2-imgheight/2
		vertpos=Math.max(pgyoffset, vertpos)
		if(crossobj.style.visibility != "visible"){
			crossobj.style.left=horzpos+"px"
			crossobj.style.top=vertpos+"px"
		}
		

		
		/*
		 * contenu de la popup
		 */
		var html='<div align="right" id="dragbar" >'
				
				+'<img title="taille reduite" src="'+img_out+'" id="imgTailleDemi" onClick="changerTaille(\'imageId\',\''+h+'\',\''+w+'\')">'
				+'<img title="taille normale" src="'+img_in+'" id="imgTailleNorm" onClick="changerTaille(\'imageId\',\''+h+'\',\''+w+'\')">'
				//+'<a href="image.php5?ida='+ida+'&cpy=0&src='+image+'" >debug</a>'
                //+'<a href="image.php5?ida='+ida+'&cpy=0&src='+image+'"  rel="lightbox" title="test" >affichage en grand</a>'
                +'&nbsp;&nbsp;'
				+'<span id="closetext" onClick="closepreview()">'
				+'<font size="1" face="verdana">Fermer</font>'
				+'</span>'
				+'</div>'
 				//+'<img oncontextmenu="return false" ondragstart="return false" onselectstart="return false" style="cursor:pointer;" alt="image" src="image.php5?ida='+ida+'&cpy=0&src='+image+'" width="'+imgwidth+'" height="'+imgheight+'" id="imageId" onclick="changerTaille(\'imageId\',\''+h+'\',\''+w+'\')">'
 				//+'<img oncontextmenu="return false" ondragstart="return false" onselectstart="return false" style="cursor:pointer;" alt="'+image+'" src="'+image+'" width="'+imgwidth+'" height="'+imgheight+'" id="imageId" onclick="changerTaille(\'imageId\',\''+h+'\',\''+w+'\')">'
	  			+ '<div>'
				+ '<img style="cursor:pointer;"' 
					+ 'alt="image"'
					+ 'src="image.php5?ida='+ida+'&cpy=1&src='+image+'"'
					//+ 'src="'+image+'"'
					+ 'id="imageId"' 
					+ 'onclick="changerTaille(\'imageId\',\''+h+'\',\''+w+'\')"'
					+ 'oncontextmenu="return false"'
					//+ 'ondragstart="return false"'
					//+ 'onselectstart="return false"'
					+ 'width="'+imgwidth+'"' 
					+ 'height="'+imgheight+'"'
					+ ' />'
				+ '</div>'
				//+ '<div id="image_zoom" style="position:relative;border:1px solid black;"></div>'
				+ '<div id="AWpopupDesc" onClick="" >'
				+  description
				+ '</div>'
				;
			
		crossobj.innerHTML=html					// contenu de la popup
		crossobj.style.width = imgwidth+"px"	// taille de la popup
		crossobj.style.visibility="visible"		// affichage

        /*
		MojoZoom.makeZoomable(  
     		document.getElementById("imageId"),   
     		'image.php5?ida='+ida+'&cpy=0&src='+image,  
     		document.getElementById("image_zoom"),  
     		100, 100  
 		);  
        */
		/*
		 * div du contenu
		 */
		crossobj2=document.getElementById? document.getElementById("image_zoom") : document.all.image_zoom
		crossobj2.style.height=+imgheight/4+"px"
		crossobj2.style.width=+imgwidth-2+"px"
		//crossobj2.style.display = "none";
		//crossobj2.style.left=(imgwidth-2)+"px"
		//crossobj2.style.top="1px"
		return false
				
	}else return true
}

function ietruebody(){
	return (document.compatMode!="BackCompat")? document.documentElement : document.body
}

/*
 * Change la taille de la popup
 *
 */
function changerTaille(img,h,w){
	
	 /* image réduite ou non */
	if(reduction==1){
		reduction=0;
	}
	else{
		w=w/2;
		h=h/2;
		reduction=1;
	}
	
	/*
	 * changement des dimensions
	 */
	crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
	image=document.getElementById? document.getElementById(img) : document.all.showimage	
	image.width=w
	image.height=h
	crossobj.style.width = w+"px"
	
	/*
	 * changement des petites images (zoom)
	 */
	i1=document.getElementById? document.getElementById("imgTailleDemi") : document.all.showimage
	i2=document.getElementById? document.getElementById("imgTailleNorm") : document.all.showimage
	if(reduction==1){
			i1.src="./inter/images/icon/zoom_out_nb.gif"
			i2.src="./inter/images/icon/zoom_in.gif"
	}
	else{
			i1.src="./inter/images/icon/zoom_out.gif"
			i2.src="./inter/images/icon/zoom_in_nb.gif"
	}
	
	/* 
	 * replacement de l'image au centre
	 */
	pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
	var horzpos=ns6? pageXOffset+window.innerWidth/2-w/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-w/2
	var vertpos=ns6? pgyoffset+window.innerHeight/2-h/2 : pgyoffset+ietruebody().clientHeight/2-h/2
	if (window.opera && window.innerHeight) vertpos=pgyoffset+window.innerHeight/2-h/2
	vertpos=Math.max(pgyoffset, vertpos)
	crossobj.style.left=horzpos+"px"
	crossobj.style.top=vertpos+"px"

}

function closepreview(){
	crossobj.style.visibility="hidden"
}

function drag_drop(e){
	if (ie&&dragapproved){
		crossobj.style.left=tempx+event.clientX-offsetx+"px"
		crossobj.style.top=tempy+event.clientY-offsety+"px"
	}
	else if (ns6&&dragapproved){
		crossobj.style.left=tempx+e.clientX-offsetx+"px"
		crossobj.style.top=tempy+e.clientY-offsety+"px"
	}
	return false
}

function initializedrag(e){
	if (ie&&event.srcElement.id=="dragbar"||ns6&&e.target.id=="dragbar"){
		offsetx=ie? event.clientX : e.clientX
		offsety=ie? event.clientY : e.clientY
		tempx=parseInt(crossobj.style.left)
		tempy=parseInt(crossobj.style.top)
		dragapproved=true
		document.onmousemove=drag_drop
	}
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")

