var IMG_MAX_WIDTH = 490;

/**
* Si la taille d'un ialge est supérieure à IMG_MAX_WIDTH,
* alors l'image est retaillé et on peut l'agrandir par un click
* @param imgNode tag img afficher sur la page
* @param imgurl url de l'image à afficher
*/
function imageSizer(imgNode,imgurl)
{
	var limg = new Image();
	limg.onload = function()
	{
		if(this.width>IMG_MAX_WIDTH)
		{
			imgNode.oldWidth = this.width;
			imgNode.oldHeight = this.height;
			imgNode.width=IMG_MAX_WIDTH;
			imgNode.style.cursor="pointer";
			imgNode.onclick = function(e)
							{
								var evt = JSTool.getEvent(e);
								var img = JSTool.getEventTarget(evt);
								openImgCenter("newwindow",img);
							};
		}
		imgNode.onload=null;
		imgNode.src= imgurl;
	};
	limg.src = imgurl;
}

/**
* Ouverture d'une image dans une pop-up de taille max
* @param name nom de la popup
* @param img image à grossir
*/
var IMG_WIN = new Array();
function openImgCenter(name,img)
{
 if(IMG_WIN[name] && !IMG_WIN[name].closed) IMG_WIN[name].close();
 var sw = screen.width;
 var sh = screen.height;
 var h = Math.min(sh-50,img.oldHeight+20);
 var w = Math.min(sw-50,img.oldWidth+20);
 var sc = w<img.oldWidth || h<img.oldHeight?"yes":"no";
 var x = (sw-w)/2;
 var y = (sh-h)/2;
 IMG_WIN[name] = window.open(img.src,name,"menubar=no,status=no,toolbar=no,top="+y+",left="+x+",width="+w+",height="+h+",scrollbars="+sc);
 IMG_WIN[name].opener = window;
 IMG_WIN[name].focus();
}

/**
* Ouverture d'une image dans une pop-up de taille max à partir d'un vignette
* @param aName nom de la popup
* @param aUrl de l'image image à grossir
*/
function openGalleryCenter(aName,aUrlimg)
{
 document.body.style.cursor = 'wait';
 var img = new Image();
 img.onload = function()
 {
 	window.status="";
 	this.oldWidth = this.width;
 	this.oldHeight = this.height;
 	openImgCenter(aName,this);
	document.body.style.cursor = 'default';
 };
 img.onerror = function() {window.status="";alert("impossible de charger l'image "+ aUrlimg);document.body.style.cursor = 'default';};
 img.src = aUrlimg;
 window.status="Image loading ....";
}

function togglePlusMinus(aElm, aRootPath, aId){
	if(aElm.state != "-"){
		aElm.state = "-";
		aElm.src = aRootPath + "link_minus_red.gif";
		document.getElementById(aId).style.display = "block";

	}else{
		aElm.state = "+";
		aElm.src = aRootPath + "link_cross_red.gif";
		document.getElementById(aId).style.display = "none";
	}
}
