function initRandomImage( id, tDiapo, width, height ){
	
	var nbImage = 0;
	var tImageOff = [], tImageOn = [], rePath;
	var sPath, sFileName, iPos;
	var oImage = document.images["ri" + id];
	if (!oImage) return;
	
	for ( var it = 0 ; it < tDiapo.length ; it++ ){
		iPos = tDiapo[it].path.lastIndexOf( "/" );
		if ( iPos != -1 ){
			sPath = tDiapo[it].path.substring( 0, iPos + 1 );
			sFileName = tDiapo[it].path.substring( iPos + 1 );;
			if ( /^_/.test( sFileName ) ){ // image on
				tImageOn[ tImageOn.length ] = {id: tDiapo[it].id, name: tDiapo[it].name, path: sPath, filename: sFileName};
			}else{ // image off
				tImageOff[ tImageOff.length ] = {id: tDiapo[it].id, name: tDiapo[it].name, path: sPath, filename: sFileName};
			}
		}
	}
	
	if ( tImageOff.length != 0 ){
		var iIndex = Math.floor( Math.random() * ( tImageOff.length ) );
		// oImage.src = tImageOff[iIndex].path + tImageOff[iIndex].filename;
		oImage.src = thumbsImage(tImageOff[iIndex].id, width, height );
		// alert( thumbsImage(tImageOff[iIndex].id, width, height ) );
		//if (width != 0) oImage.width = width;
		//if (height != 0) oImage.height = height;
		
		for ( var it = 0; tImageOn.length ; it++ ){
			if ( ("_" + tImageOn[ it ].filename == tImageOff[iIndex].filename)
				  || ( tImageOn[ it ].name == tImageOff[iIndex].name) ){
				oImage.onmouseover = function(){ oImage.src = thumbsImage( tImageOn[iIndex].id, width, height ); }; 
				oImage.onmouseout = function(){ oImage.src = thumbsImage( tImageOff[iIndex].id, width, height ); }; 
				// on precharge l'image on
				var oImgCache = new Image();
				oImgCache.src = thumbsImage( tImageOn[iIndex].id, width, height );
				
				break;
			}
		}
	}else{
		oImage.style.display = "none" ;
	}

}

function thumbsImage( id, width, height ){
	var thumbsPath = retrieveRootPath();
	
	// thumbsPath = "http://192.168.0.220/luna-libre";
	
	var iW = width || 0;
	var iH = height || 0;
	
	thumbsPath += "pages/misc/thumbs.asp";
	thumbsPath += "?__c=1&id=" + id;
	if ( iW != 0 ) thumbsPath += "&iW=" + iW;
	if ( iH != 0 ) thumbsPath += "&iH=" + iH;
	
	//console.debug(thumbsPath);
	
	return thumbsPath;
}

function retrieveRootPath( aPath ){
	var path = aPath || document.URL;
	var REurl = new RegExp( "http://[^/]*/[^/]*/" );
	var tUrl = REurl.exec( path );
	var url = null;
	
	if ( tUrl ){
		url = tUrl[0];
	}
	
	return url;
	
	/*
	var pos1 = -1 , pos2 = -1;
	path = path.replace( /http:\/\//, "" );
	pos1 = path.indexOf( "/" );
	if ( pos1 != -1 ){
		pos2 = path.indexOf( "/", pos1 + 1 );
	
	}
	if ( pos1 == -1 || pos2 == -1 )
		return "";
	return path.substring( pos1, pos2 );
	*/
}