// BASIC VARIABLES

numimages = 8; // total number of images, including "0"
pixdir = '/gallery/'; //must end in slash
prefix = 'soir';


navdisplay = 5; // number to show at a time
thumbwidth = 60;
thumbheight = 60;
mainwidth = 320;
mainheight = 320;
navprevious = 'pr&eacute;c&eacute;dent';
navnext = 'suivant';
navenlarge = 'imprimer';

// no changes below this line



if (navdisplay > numimages) { navdisplay = numimages };
halfpix = Math.floor(navdisplay/2);
if (halfpix == navdisplay/2) { halfpix-- }

firstimage= numimages - halfpix;
currentimage = halfpix;


// LOAD THUMBNAILS AND MAIN IMAGES
thumbnail=new Array();
mainpic=new Array();
pixaction=new Array();
enlargepic=new Array();
var i = 0;
var thisimage = numimages - halfpix;
while (i < numimages) {
	thumbnail[i]=new Image;
	mainpic[i]=new Image;
	thumbnail[i].src = pixdir + prefix + 'th' + i + '.jpg';
	mainpic[i].src = pixdir + prefix + i + '.jpg';
	enlargepic[i] = pixdir + prefix + 'big' + i + '.jpg';
	pixaction[i] = thisimage;
	thisimage++;
	if (thisimage >= numimages) { thisimage = 0 }		
	i++;
}

function insertnav() {

	// UP NAVIGATION
	document.write('<div id="uppix" style="text-align:center; margin:0 auto 5px auto"><a href="#" onclick="navup();return false"><img src="' + pixdir + 'prevarrow.gif" width="42" height="28" border="0" alt="" /></a></div>');

	// THUMBNAILS
	var i=0;
	document.write('<div>');
	while (i < navdisplay) {
		document.write('<a href="#" onclick="refocuspix(\'' + i + '\');return false;">');
		document.write('<img src="' + thumbnail[pixaction[i]].src + '" width="' + thumbwidth + '" height="' + thumbheight + '" alt="" border="0" id="thumbpix' + i + '"');
		if (i == halfpix) {
			document.write(' style="border: 3px #fff solid"');
		}
		document.write(' />');
		document.write('</a>');
		i++;
	}
	document.write('</div>');
	
	// DOWN NAVIGATION
	document.write('<div id="downpix" style="text-align:center; margin:5px auto 0 auto"><a href="#" onclick="navdown();return false"><img src="' + pixdir + 'nextarrow.gif" width="42" height="28" border="0" alt="" /></a></div>');
}

function insertmainimage() {

	// DRAW THE MAIN IMAGE
	document.write('<div id="mainpixframe"><div id="mainpixdisplay">');
	document.write('<a href="' + enlargepic[0] + '" id="mainpixenlarge" target="_blank"><img src="' + mainpic[0].src + '" width="' + mainwidth + '" height="' + mainheight + '" alt="" border="0" id="mainpiximage" /></a>');
	document.write('</div>');
	
	//DRAW PREVIOUS/ENLARGE/NEXT/
	document.write('<div style="float:left;width:100px"><a href="#" onclick="prevpic();return false;">&laquo; ' + navprevious + '</a></div>');
	document.write('<div style="float:right;width:100px;text-align:right"><a href="#" onclick="nextpic();return false;">' + navnext + ' &raquo;</a></div>');
	document.write('<div style="width:150px;margin:0 auto;text-align:center"><a href="' + enlargepic[0] + '" id="pixenlarge" target="_blank">' + navenlarge + '</a></div>');

	document.write('</div>');

}


function showpix(pixid) {
	document.getElementById('mainpiximage').src = mainpic[pixaction[pixid]].src;
	document.getElementById('pixenlarge').href = enlargepic[pixaction[pixid]];
	document.getElementById('mainpixenlarge').href = enlargepic[pixaction[pixid]];
}


function redrawpix() {
	var i = 0;
	var thisimage = firstimage;
	while (i<navdisplay) {
		document.getElementById('thumbpix' + i).src = thumbnail[thisimage].src;
		pixaction[i]=thisimage;
		thisimage++;
		i++;
		if (thisimage >= numimages) { thisimage = 0 }
	}
}

function navup() {
	firstimage--;
	if (firstimage < 0) { firstimage = numimages - 1 }
	redrawpix();
	showpix(halfpix);
}

function navdown() {
	firstimage++;
	if (firstimage >= numimages) { firstimage = 0 }
	redrawpix();
	showpix(halfpix);
}

function nextpic() {
	navdown();

}

function prevpic() {
	navup();
}

function refocuspix(pixid) {
	firstimage = pixaction[pixid] - halfpix;
	if (firstimage < 0) { firstimage = numimages + firstimage }
	redrawpix();
	showpix(halfpix);
}


