
// variable globales
var tabImageToResize = new Array();
var tabMaxWidth = new Array();
var tabMaxHeight = new Array();
var maxWidthDefault = 200;
var maxHeightDefault = 200;

function addImageToResize(image, width, height){

		tabImageToResize[tabImageToResize.length] = image;
		if(width!=null){
			tabMaxWidth[tabMaxWidth.length] = width;
		} else {
			tabMaxWidth[tabMaxWidth.length] = maxWidthDefault;
		}
		if(height!=null){
			tabMaxHeight[tabMaxHeight.length] = height;
		} else {
			tabMaxHeight[tabMaxHeight.length] = maxHeightDefault;
		}
		
}

function resizeOnLoad(){
	var i =0;
	for(i; i<tabImageToResize.length; i++){
		resizeImage(tabImageToResize[i], tabMaxWidth[i] , tabMaxHeight[i]);
	}
}

//*******************************************************************************//
//*   Function  resizeImage(image, maxWidth, maxHeight)                         *//
//*           image     = lien vers l'image à retailler <img>                   *//
//*           maxWidth  = Taille maximum en larguer                             *//
//*           maxHeight = Taille maximum en hauteur                             *//
//*      ex : <img name="Image" src="image.gif" onLoad="resizeImage(this, 10, 20, false );"/>   *//
//*           l'image n'est retaillée que si elle dépasse les bornes            *//
//*******************************************************************************//
function resizeImage(image, maxWidth, maxHeight){
	var iWidth = image.width;
	var iHeight = image.height;
	var tauxWidth = 100;
	var tauxHeight = 100;
	//debugDump(image);
	//alert("avant : "+image+" "+image.width+" "+image.height);
	//alert(iWidth+" "+iHeight);	
	if(iWidth > maxWidth || iHeight > maxHeight){
		if(iWidth > maxWidth) tauxWidth = 1 - ((iWidth - maxWidth) / iWidth);
		if(iHeight > maxHeight) tauxHeight = 1 - ((iHeight - maxHeight) / iHeight);
		//alert(tauxWidth+" "+tauxHeight);
		if(tauxWidth < tauxHeight){
			image.width=iWidth * tauxWidth;
			image.height=iHeight * tauxWidth;
		} else {
			image.width=iWidth * tauxHeight;
			image.height=iHeight * tauxHeight;
		}
	}
	//alert("après : "+image.width+" "+image.height);
}

//---------------------------------------------------------------
// Fonction qui liste le contenu d'un objet javascript
//---------------------------------------------------------------
   function debugDump(obj) {
//---------------------------------------------------------------//

if (typeof(obj) != 'undefined')
{
	var str="";
		str += '<BR>**********************<BR>' + obj+'<BR>**********************<BR>';
		
	for (var i in obj)
	{
		if (typeof(obj[i]) != "unknown")
		{
				str = str+i+"="+obj[i]+'<BR>';
		}

 	}
		str += '<BR>**********************<BR>Style de ' + obj+'<BR>**********************<BR>';

	if (obj.style) 
	{
		for (var j in obj.style)
		{
			if (typeof(obj.style[j]) != "unknown")
			{
					str = str+j+"="+obj.style[j]+'<BR>';
			}
		}
	}

	if (obj.item) 
	{
 		for (i=0;i<obj.length;i++)
 		{
	 			str += '**********************<BR>' + obj[i]+'<BR>**********************<BR>';
	 		
 			for (var j in obj[i])
 			{
					str = str+j+"="+obj[i][j]+'<BR>';
 			}

	 			str += '**********************<BR>Style de ' + obj[i]+'<BR>**********************<BR>';

 			for (var j in obj[i].style)
 			{
					str = str+j+"="+obj[i].style[j]+'<BR>';
 			}
 		}
 	}
 	w = window.open("","debugWindow");
 	w.document.open();
 	w.document.write(str);
 	w.document.close();
}
}

