function swapImgRestore() //v3.0 
{
  var i,x,a=document.sr; 
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
  	x.src=x.oSrc;
}

function preloadImages()  //v3.0
{
  var doc=document; 
  if(doc.images)
  { 
    if(!doc.picsArray)
      doc.picsArray=new Array();
    var i,j=doc.picsArray.length,a=preloadImages.arguments; 
	for(i=0; i<a.length; i++)
	{
      if (a[i].indexOf("#")!=0)
	  { 
		doc.picsArray[j]=new Image; 
		doc.picsArray[j++].src=a[i];
	  }
	}
  }
}

function findObj(n, doc) //v4.0 
{
  var p,i,x;  
  if(!doc) 
  	doc=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) 
  {
    doc=parent.frames[n.substring(p+1)].document; 
	n=n.substring(0,p);
  }
  if(!(x=doc[n])&&doc.all) 
    x=doc.all[n]; 
  for (i=0;!x&&i<doc.forms.length;i++) 
    x=doc.forms[i][n];
  for(i=0;!x&&doc.layers&&i<doc.layers.length;i++) 
    x=findObj(n,doc.layers[i].document);
  if(!x && document.getElementById) 
    x=document.getElementById(n); 
  return x;
}

function swapImage() //v3.0 
{	
  var i,j=0,x,a=swapImage.arguments; 
  document.sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
  {
   if ((x=findObj(a[i]))!=null)
   {
     document.sr[j++]=x; 
	 if(!x.oSrc) 
	   x.oSrc=x.src; 
	 x.src=a[i+2];
   }
  }
}

function displayImage(target, imageNum, sourceItem)
{
	var tgt = findObj(target);
	if(tgt != null)
	{
		tgt.src = document.picsArray[imageNum - 1].src;
		tgt.id = imageNum;
	}
	if(sourceItem != null)
		sourceItem.style.border = "1px black";
		
	//disable the 'next' button if we're at the end 
	//disable the 'prev' button if we're at the beginning
	var oCollNext = document.getElementsByName("suivant");
	var oCollPrev = document.getElementsByName("dernier");
	if(oCollNext != null && oCollPrev != null)
	{
		for(i = 0; i<oCollNext.length; i++)
			oCollNext[i].disabled = false;
		for(i = 0; i<oCollPrev.length; i++)
			oCollPrev[i].disabled = false;
		if(imageNum == 1)
		{
			for(i = 0; i<oCollPrev.length; i++)
				oCollPrev[i].disabled = true;	
		}
		else if(imageNum == document.picsArray.length)
		{
			for(i = 0; i<oCollNext.length; i++)
				oCollNext[i].disabled = true;
		}
	}		
}

//displays the next image in the series, if we're already on the last image, displays
//the first image again
//the target name represents the number of the image, the id is used to locate the image
function nextImage(target)
{
	var tgt = findObj(target);
	if(tgt != null && tgt.id != null)
	{
              //forces the id to be treated as a number 
              //and then add one to advance to the next image
		var img_num = (tgt.id * 1) + 1;
		if(img_num > document.picsArray.length) img_num = 1;
		displayImage(target, img_num);
	}   
			
}

//displays the previous image in the series, if we're already on the first image, displays
//the last image 
//the target name represents the number of the image, the id is used to locate the image
function prevImage(target)
{
	var tgt = findObj(target);
	if(tgt != null && tgt.id != null)
	{
		//forces the id to be treated as a number 
		//and then subtract one to move to the previous image
		var img_num = (tgt.id * 1) - 1;
		if(img_num < 1) img_num = document.picsArray.length;
		displayImage(target, img_num);
	}   
			
}
