
var backColor = '#FFFFFF';

function initParamsPhoto(boutonImageFermer)
{
	//Bloc de param?trage de la fen?tre (popup photo)
	var paramsPhoto =  	
	{	
	   BorderColor : '#FFFFFF', 
	   BorderWidth : 0, 
	   CloseBoxHeight : 10, 
	   CloseBoxSrc : boutonImageFermer,
	   CloseBoxWidth : 55, 
	   ContentColor : backColor, 
	   ContentBottomBorderColor : '#FFFFFF', 
	   ContentHTML : '', 
	   ContentPadding : 0, 
	   Height : 300, 
	   InnerBorderColor : '#FFFFFF', 
	   InnerBorderWidth : 12, 
	   OuterBorderColor : '#D4D4D4', 
	   Resizable : 'None', 
	   ResizeBoxHeight : 7, 
	   ResizeBoxWidth : 7, 
	   Shadow : true, 
	   StatusBarHeight : 0, 
	   StatusColor : 'white', 
	   TitleBarHeight : 4, 
	   TitleColor : '#FFFFFF', 
	   Width : 260, 
	   TitleFontSize : 6, 
	   ContentFontColor : '#5559EA', 
	   StatusFontSize : 6, 
	   Id  : 'DHTMLPhotoPopup'
	}
 	DHTMLPhotoPopup = new FerantDHTMLWindow(paramsPhoto); //Objet fen?tre
}

var DHTMLPhotoPopup;
var tabRefImages	= new Array();
var tabTaillesImages = new Array();
var flechePrec = "";
var flecheSuiv = "";


/**************************************************
/ Fonction permettant d'initialiser le contenu de 
/ la fen?tre avec l'image pass?e en param?tre
***************************************************/
function chargeImage(no_photo)
{
	DHTMLPhotoPopup.UpdateContentHTML(fillContent(no_photo, 5));
}

/**************************************************
/ Fonction permettant d'initialiser le contenu de 
/ la fen?tre avec l'image pass?e en param?tre - Image v?ritable
***************************************************/
function chargeImageFull(no_photo)
{
	DHTMLPhotoPopup.UpdateContentHTML(fillContentWithImages(no_photo, 5));
}


/**************************************************
/ Fonction permettant l'ouverture d'une fen?tre
/ avec du texte format HTML
***************************************************/
function OpenTexteWindow(contentText, popup)
{
	
	DHTMLPhotoPopup.CloseWindow();
	
	DHTMLPopup.UpdateContentHTML(contentText);
	DHTMLPopup.OpenWindow();
		
}

/**************************************************
/ Fonction permettant l'ouverture d'une fen?tre
/ avec du texte format HTML, utilis? pour les images
***************************************************/
function OpenTexteWindowForImages(contentText)
{
	DHTMLPhotoPopup.CloseWindow();
	DHTMLPopup.CloseWindow();
	
	DHTMLPhotoPopup.UpdateContentHTML(contentText);
	DHTMLPhotoPopup.OpenWindow();
}

/**************************************************
/ Fonction permettant l'ouverture d'une fen?tre
/ avec la photo no_photo affich?e ainsi que les
/ liens vers les autres photos
***************************************************/
function OpenImageWindow(pImageTable, pathPrev, pathNext)
{
	tabRefImages = pImageTable;
	flechePrec = pathPrev;
	flecheSuiv = pathNext;

	// On remplit un tableau d'images pour avoir les tailles des images par defaut
	for( i=0; i < tabRefImages.length; i++)
	{
		image = new Image();
		image.src = tabRefImages[i];
		tabTaillesImages[i] = image;
	}	
	
	DHTMLPhotoPopup.UpdateContentHTML(fillContent(1, 5));
	DHTMLPhotoPopup.OpenWindow();
}


/**************************************************
/ Fonction permettant de g?n?rer le code HTML
/ en fonction de l'image ? afficher
/ On passe en param?tre le nombre de liens par page
/ La hauteur et la largeur seront d?finies en param?tres externes.
***************************************************/
function fillContent(no_photo, nbImageParPage)
{
	nbImage = tabRefImages.length;
	
	lienComplet	= '<table width="100%" height="255" border="0" cellspacing="0" cellpadding="0">\n<tr height="230">\n<td colspan=3 align="center" valign="center">'
	
	if (nbImage > 0)		//Init si il y a au moins une photo
	{
		if( tabTaillesImages[no_photo-1].width > tabTaillesImages[no_photo-1].height )
		{
			largeur = 215;
			hauteur = 150;
		}
		else
		{
			largeur = 150;
			hauteur = 215;
		}
		lienComplet += '<img src="' + tabRefImages[no_photo - 1] + '" width="'+largeur+'" height="'+hauteur+'">\n </td>\n';
	}
	else					//Sinon affiche une fen?tre vide
		return '</tr>\n';
		
		
	if (nbImage > 1)
	{// dans le cas o? il y a plusieurs photos, on affiche les liens pour atteindre les autres
		lienComplet	+= '<tr height="20">\n<td width="10%" align="left">\n'
		if (no_photo > 1 )	//Lien vers l'image pr?c?dente si elle existe
			lienComplet += '<a class="lienphoto" href="JavaScript:chargeImage(' + (no_photo - 1) + ')"><img src="'+flechePrec+'" border="0"></a>\n';
			
		lienComplet	+= '</td>\n<td align="center" valign="top" width="80%">\n'

		from	= 1;
		end		= nbImage;
		if( nbImage > nbImageParPage )
		{
			from	= Math.max(1, Math.min(nbImage, no_photo - Math.ceil(nbImageParPage / 2) + 1 ) );
			end		= Math.min( nbImage, from + (nbImageParPage - 1) );
			
			
			if( from > (nbImage - nbImageParPage + 1) )
				from	= nbImage - nbImageParPage + 1;
				
		}
		
		
		for( var i = from ; i <= end ; i++)
		{// On affiche les liens autour de la photo courante par bloc de nbImageParPage photos
			if ( i == no_photo )	//Pas de lien vers la photo courante
				lienComplet += '<a class="offrePagecourante">' + i + '</a> &nbsp;\n';
			else
				lienComplet += '<a class="offrePage" href="JavaScript:chargeImage(' + i + ')">' + i + '</a> &nbsp;\n';
		}
		
		lienComplet	+= '</td>\n<td width="10%" align="right">\n'
		if (no_photo < nbImage )	//Lien vers l'image suivante si elle existe
			lienComplet += ' <a class="lienphoto" href="JavaScript:chargeImage(' + (no_photo + 1) + ')"><img src="'+flecheSuiv+'" border="0"></a>\n';
		lienComplet	+= '</td>\n</tr>\n</table>\n'
	}

	//retourne le code g?n?r?.
	return lienComplet;
	
}

