//	Dimensions et répertoires par défaut
var PGC = 480, PPC = 360;
var Miniatures = "../miniatures/", Photos = "../photos/";

//	Variables globales
var DimPhoto = new RegExp("^[0-9]{3}[xX][0-9]{3}$"), PL, PH, ML, MH;
var Photo = null;

//	Usage :
//		var Liste = new Array()
//		Liste[0] = "Nom[, Format[, Commentaire]]"
//		Liste[n] = ...
//		Gallerie(Liste[, "../miniatures/"[, "../photos/"]])
//
//			Format = L ou P ou NNNxNNN
//			où L = DimPhoto par défaut, mode paysage (défaut)
//				P = DimPhoto par défaut, mode portrait
//				NNNxNNN = DimPhoto particulières, Largeur x Hauteur
//
function Gallerie(Liste, RM, RP) {
	if (Liste == undefined) {
		alert("Script : Gallerie,\nLe nom de la gallerie est obligatoire");
		return false;
	}
	var Nom, Format, Commentaire;
	var Item = new Array(3), n;
	for (n = 0; n < Liste.length; n++) {
		Item = Liste[n].split(", ");
		if (Item[0] == undefined) {
			alert("Script : Gallerie,\nLe nom de la photo est obligatoire");
			return false;
		} else {
		   Nom = Item[0];
		}
		Format = Item[1];
		Commentaire = Item[2];
		Miniature(Nom, Format, Commentaire, RM, RP);
	}
	return true;
}

//	Usage :
//		Miniature("Nom"[, "Format"[, "Commentaire"[, "Miniatures"[, "Photos"]]])
//
function Miniature(Nom, Format, Commentaire, RM, RP) {
	if (Nom == undefined) {
		alert("Script : Miniature,\nLe nom de la photo est obligatoire");
		return false;
	} else {
		Nom = escape(Nom);
	}
	if (Format == undefined) Format = "L";
	if (Commentaire == undefined) Commentaire = "<>"; else Commentaire = escape(Commentaire);
	if (RM == undefined) RM = Miniatures;
	if (RP == undefined) RP = Photos;
   setDimensions(Format);
	with (document) {
		write ('<a chref="#" onClick=\'PopUpPhoto("' + RP + Nom + '",' + PL + ',' + PH  + ',"' + Commentaire + '");return false;\'>');
		write ('<img class="miniature" src="' + RM + Nom + '" width="' + ML + '" height="' + MH + '" alt="' + Commentaire + '" title="Cliquez pour agrandir" />');
		write ('</a>');
	}
	return true;
}

function setDimensions (Format) {
	switch(Format) {
		case ("L") :
			PL = PGC;
			PH = PPC;
			break;
		case ("P") :
			PL = PPC;
			PH = PGC;
			break;
		default :
			if (DimPhoto.test(Format)) {
 				PL = Format.substr(0,3);
				PH = Format.substr(4,3);
			} else {
				alert("Script : Miniature,\nDimensions de photo invalides : " + Format);
				return false;
			}
	}
	ML = PL / 3;
	MH = PH / 3;
	return true;
}

function PopUpPhoto(URL, Largeur, Hauteur, Commentaire) {
	var LargeurFenetre = Largeur + 40;
	var HauteurFenetre = Hauteur + 110;
	var Left = (window.screen.width - LargeurFenetre) / 2;
	var Top = (window.screen.height - HauteurFenetre) / 2;
	var Page = "Photo.html?P=" + URL + "&L=" + Largeur + "&H=" + Hauteur + "&C=" + Commentaire;
	var Configuration = "dependent=yes, left=" + Left + ", top=" + Top +
		", width=" + (LargeurFenetre) + ", height=" + (HauteurFenetre) +
		", resizable=no, directories=no, location=no, menubar=no, scrollbars=no, statusbar=no, toolbar=no";
	if (Photo != null) if(! Photo.closed) Photo.close();
	Photo = window.open(Page, 'Photo', Configuration);
	Photo.focus();
	return true;
}

function DisplayPhoto() {
	var Parametres = window.location.search.substring(1).split("&");
	var Parametre = new Array(2), n;
	for (n = 0; n < Parametres.length; n++) {
		Parametre = Parametres[n].split("=");
		switch (Parametre[0]) {
			case ("P") :
				var Photo = Parametre[1];
				break;
			case ("L") :
				var Largeur = Parametre[1];
				break;
			case ("H") :
				var Hauteur = Parametre[1];
				break;
			case ("C") :
				var Commentaire = Parametre[1];
				break;
		}
	}
	with (document) {
		write('<p><strong>' + unescape(Commentaire) + '</strong></p>');
		write('<p>');
		write('<a href="javascript:window.close()">');
		write('<img class="photo" src="' + Photo + '" width="' + Largeur + '" height="' + Hauteur  + '" title="Cliquez pour fermer" />');
		write('</a><br />');
		write('Cliquez sur la photo pour la fermer');
		write('</p>');
	}
	return true;
}

