// SlideShow with Captions and Cross-Fade
// (C) 2002 www.CodeLifter.com
// http://www.codelifter.com
// Free for all users, but leave in this header.

// ==============================
// Set the following variables...
// ==============================

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 5000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 2;


var tss;
var jss = 0;
var iss = 0;

var preLoad = new Array();
var arrCaptions = new Array();
var arrWidth = new Array();
var arrHeight = new Array();

/*
function runSlideShow() {
  //alert("Dia:" + jss + " " + preLoad[jss].src);
  if ( document.getElementById('picture') ) {
    if (document.all){
      //document.getElementById('picture').style.filter="blendTrans(duration=2)";
      document.getElementById('picture').style.filter="blendTrans(duration=CrossFadeDuration)";
      document.getElementById('picture').filters.blendTrans.Apply();
    }
    document.getElementById('picture').setAttribute('width', arrWidth[jss]);
    document.getElementById('picture').setAttribute('height', arrHeight[jss]);
    document.getElementById('picture').src = preLoad[jss].src;
    if (document.all){
      document.getElementById('picture').filters.blendTrans.Play();
    }
    if ( document.getElementById('caption') ) {
      document.getElementById('caption').innerHTML = arrCaptions[jss];
    }
  }

  jss = jss + 1;
  if (jss > (iss - 1)) jss=1;
  tss = setTimeout('runSlideShow()', SlideShowSpeed);
}
*/

function runSlideShow()
{
	if(iss > 1){
	   var img = $('picture');
	
	   //Element.hide('picture');
	   img.style.display = 'none';
	   img.src = '';
	     
	   img.setAttribute('width', arrWidth[jss]);
	   img.setAttribute('height', arrHeight[jss]);
	   img.src = preLoad[jss].src;
	   
	   //new Effect.Appear('picture');
	   img.style.display = 'block';
	   if ( document.getElementById('caption') ) {
	   	$('caption').innerHTML = arrCaptions[jss];
	   }
	
	   if (jss < (iss - 1)) jss++;
	   else{
	    jss = 0;
	   }
	
	   window.setTimeout("runSlideShow()",SlideShowSpeed);
   }
}

function addPicture(pictureURL, caption, width, height)
{
  preLoad[iss] = new Image();
  preLoad[iss].src = pictureURL;
  arrCaptions[iss] = caption;
  arrWidth[iss] = width;
  arrHeight[iss] = height;
  iss = iss + 1;
}


function previousImg()
{
  var iCurrentVisuel = parseInt(document.getElementById('currentVisuelNb').innerHTML);
  var iNbVisuels = parseInt(document.getElementById('nbVisuels').innerHTML);
  // alert(iCurrentVisuel);
  if (iCurrentVisuel == 1)
  {
     iCurrentVisuel = iNbVisuels;
  }
  else
  {
     iCurrentVisuel--;
  }
  document.getElementById('currentVisuelNb').innerHTML = iCurrentVisuel;
  showImg(iCurrentVisuel);
}

function nextImg()
{
  var iCurrentVisuel = parseInt(document.getElementById('currentVisuelNb').innerHTML);
  var iNbVisuels = parseInt(document.getElementById('nbVisuels').innerHTML);
  // alert(iCurrentVisuel);
  if (iCurrentVisuel == iNbVisuels)
  {
     iCurrentVisuel = 1;
  }
  else
  {
     iCurrentVisuel++;
  }
  document.getElementById('currentVisuelNb').innerHTML = iCurrentVisuel;
  showImg(iCurrentVisuel);
  redimensionne();
}

function showImg(iImgNumber)
{
	if ( document.getElementById('picture') ) {
    if (document.all){
      document.getElementById('picture').style.filter="blendTrans(duration=2)";
      document.getElementById('picture').style.filter="blendTrans(duration=CrossFadeDuration)";
      document.getElementById('picture').filters.blendTrans.Apply();
    }
    document.getElementById('picture').setAttribute('width', arrWidth[iImgNumber]);
    document.getElementById('picture').setAttribute('height', arrHeight[iImgNumber]);
    document.getElementById('picture').src = preLoad[iImgNumber].src;
    if (document.all){
      document.getElementById('picture').filters.blendTrans.Play();
    }
  }
}

function popUpImg()
{
	if (document.getElementById('picture'))
	{
		var tabSRC = document.getElementById('picture').src.split("_");
		var img_to_zoom_src = document.getElementById('picture').src.replace("diapo", "600");
		
		var iLastSlash = img_to_zoom_src.lastIndexOf('/');
		var host = img_to_zoom_src.substring(0, iLastSlash + 1);
		var img_name = img_to_zoom_src.substr(iLastSlash + 1);
		var myReg = new RegExp("^_[a-zA-Z0-9]{3}_");
		var new_img_name = img_name.replace(myReg, '');
		var complet_new_src = host + new_img_name;
		complet_new_src = escape(complet_new_src);
		
		// Xiti des popup des images
		if (xtpage != undefined) {
			var sXtpage = xtpage.split('::');
			var sName = img_to_zoom_src.split('/');
			sXtpage[(sXtpage.length - 1)] = 'photo_' + sName[(sName.length - 1)].toLowerCase();
			sXtpage = sXtpage.join('::');
		}
		else {
			var sXtpage = '';
		}
		
		popupcentree("../view_image.php?image=" + complet_new_src + '&xtpage=' + sXtpage, 800, 600);
	}
}

function popupcentree(page,largeur,hauteur)
{
    var top=(screen.height-hauteur)/2;
    var left=(screen.width-largeur)/2;
    var hdwnd;
					
	try
	{
        hdwnd = window.open(page,"","toolbar=no, location=no, directories=no, status=no, scrollbars=yes, resizable=yes, copyhistory=no,top="+top+",left="+left+",width="+largeur+",height="+hauteur);        
    }
    catch(erreur)
    {
        alert("erreur");
    }
    return hdwnd;
}

function zoomImg(idImg, prefix, legend)
{
	if (document.getElementById(idImg))
	{
		var img_to_zoom_src = document.getElementById(idImg).src;
		var iLastSlash = img_to_zoom_src.lastIndexOf('/');
		var host = img_to_zoom_src.substring(0, iLastSlash + 1);
		var img_name = img_to_zoom_src.substr(iLastSlash + 1)
		var myReg = new RegExp("^_[a-zA-Z0-9]{3}_");
		var new_img_name = img_name.replace(myReg, prefix);
		var complet_new_src = host + new_img_name;
		
		if (document.getElementById('picture'))
		{
			document.getElementById('picture').src = complet_new_src;
		}
		document.getElementById('legendeImage').innerHTML = legend;
	}
	setTimeout("redimensionne()", 10);
}
