/* créateur du site : Netalapage (c)2006 www.netalapage.com, sites personnalisés */
/* nom de la page   : photographies-galerie.js                                   */
/* protégé par SARL : Netalapage - création des sites Internet uniques, pas cher */

var fadeIndexPhotoWait = 2500;						/* pause to show photo */
var currentIndexPhotoOpacity = 0;					/* opacity value of current photo */
var fadeIndexPhotoSpeed = 10;						/* speed to fade photo in and out */
var fadeIndexPhotoAmount = 2;						/* amount of opacity of photo to change */

function IndexPhotoInit() {
	galleryRand = Math.floor(Math.random()*galleryNames.length);
	photoRand = Math.floor(Math.random()*galleryPhotos[galleryRand].length);
	photoFilename = 'pics-20090303/300x200/photographies-' + galleryNames[galleryRand] + '/' + galleryPhotos[galleryRand][photoRand];
	document.getElementById('photographies-grand-current').innerHTML = '<p class="h220 w360 tcenter bord1mauve pt20 backgreydarkest"><img src="' + photoFilename + '" width="300" height="200" alt="' + photoFilename + '" class="bord1mauve" /></p>';
	IndexPhotoSetNext();
}

function IndexPhotoSetNext() {
	galleryRand = Math.floor(Math.random()*galleryNames.length);
	photoRand = Math.floor(Math.random()*galleryPhotos[galleryRand].length);
	photoFilename = 'pics-20090303/300x200/photographies-' + galleryNames[galleryRand] + '/' + galleryPhotos[galleryRand][photoRand];
	photo0 = new Image; photo0.src = photoFilename;
	image = document.getElementById('photographies-grand-next');
	setOpacity(image, 0);
	image.innerHTML = '<p class="h220 w360 tcenter bord1mauve pt20 backgreydarkest"><img src="' + photoFilename + '" width="300" height="200" alt="' + photoFilename + '" class="bord1mauve" /></p>';
	setTimeout("IndexPhotoFade()", fadeIndexPhotoWait);
}

function IndexPhotoFade() {
	image = document.getElementById('photographies-grand-next');
	setOpacity(image, currentIndexPhotoOpacity);
	currentIndexPhotoOpacity += fadeIndexPhotoAmount;
	if (currentIndexPhotoOpacity >100)
		IndexPhotoChange();
	else
		window.setTimeout("IndexPhotoFade()", fadeIndexPhotoSpeed);
}

function IndexPhotoChange () {
	document.getElementById('photographies-grand-current').innerHTML = document.getElementById('photographies-grand-next').innerHTML;
	currentIndexPhotoOpacity=0; 
	IndexPhotoSetNext();
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100)?99:opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";			/* IE/WIN */
	obj.style.KHTMLOpacity = opacity/100;						/* Safari<1.2, Konqueror */
	obj.style.MozOpacity = opacity/100;							/* Older Mozilla and Firefox */
	obj.style.opacity = opacity/100;							/* Safari 1.2, newer Firefox and Mozilla, CSS3 */
}

function ChangeImage(ID, Width, Height) {
	document.getElementById('photographies-grand').innerHTML = '<p class="right h380 w590 tcenter bord1grey pt20 backgreydarkest"><img src="' + ID + '" width="' + Width + '" height="' + Height + '" alt="" class="bord1white" /></p>';
}

function openPhotoWindow(dir, counter, filename) {

	/* ensure counter numeric to perform lookup in array */
	counter = counter * 1;
	if (counter > 99) counterText = ''+counter;
		else if (counter > 9) counterText = '0'+counter;
		else counterText = '00'+counter;

	/* set value for next image and construct filename */
	counterNext = counter + 1;
	if (counterNext > 99) counterNextText = ''+counterNext;
		else if (counterNext > 9) counterNextText = '0'+counterNext;
		else counterNextText = '00'+counterNext;

	/* set value for previous image and construct filename */
	counterBack = counter - 1;
	if (counterBack > 99) counterBackText = ''+counterBack;
		else if (counterBack > 9) counterBackText = '0'+counterBack;
		else counterBackText = '00'+counterBack;

	photo0 = new Image; photo0.src = dir+counterNextText+'.jpg';
	photo1 = new Image; photo1.src = dir+counterBackText+'.jpg';

	/* set value for size part of image tag to be output */
	size = landscapeLarge;
	for(var i = 0; i < portrait.length; i++)
		if(portrait[i] === counter) size = portraitLarge;

	newtag = '<p class="galerie-grand"><p class="galerieCounter">Réf:&nbsp;&nbsp;&nbsp;'+counterText+'</p><br class="images-en-liberte" />';
	newtag = newtag + '<p class="galerie-grand"><img src="'+dir+filename+'.jpg" '+size+' alt="" /></p>';
	if (counterBack > 0) newtag = newtag + '<p class="galeriePrecedent" onclick="openPhotoWindow(\''+dir+'\',\''+counterBack+'\',\''+counterBackText+'\');" style="cursor:pointer">Précédent</p>'; else newtag = newtag + '<p class="galeriePrecedentBlank">&nbsp;</p>';
	newtag = newtag + '<p class="galerieRetour" onclick="closePhotoWindow()" style="cursor:pointer">Retour</p>';
	if (counterNext <= photosTotal) newtag = newtag + '<p class="galerieSuivant" onclick="openPhotoWindow(\''+dir+'\',\''+counterNext+'\',\''+counterNextText+'\');" style="cursor:pointer">Suivant</p>';
	document.getElementById('galerie-grand').innerHTML = newtag;
	document.getElementById('galerie-grand').style.display='block';
	document.getElementById('galerie-petit').style.opacity=0.2;
	document.getElementById('galerie-petit').style.filter='alpha(opacity=20)';
}

function closePhotoWindow() {
	document.getElementById('galerie-grand').style.display='none';
	document.getElementById('galerie-petit').style.opacity = 1;
	document.getElementById('galerie-petit').style.filter='alpha(opacity=100)';
}