//--- VARIABLES
var arrowImageHeight = 30;           // Hauteur des zones des flêches
var slideSpeed = 0;                  // Vitesse du déplacement de la bande d'images
var previewImage = false;
var previewImageParent = false;
var previewImagePane = false;
var slideEndMarker = false;
var galleryContainer = false;

//--- TRANSITIONS (IE 55 et + uniquement)
var x = new Array();
	x[0] = "progid:DXImageTransform.Microsoft.RandomDissolve()";                                                            // Dissoudre
  x[1] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=circle, motion=in, duration=1)";                               // Cercle intérieur
  x[2] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=circle, motion=out, duration=1)";                              // Cercle extérieur
  x[3] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=cross, motion=in, duration=1)";                                // Croix St André intérieur
  x[4] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=cross, motion=out, duration=1)";                               // Croix St André extérieur
  x[5] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=plus, motion=in, duration=1)";                                 // Croix intérieur
  x[6] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=plus, motion=out, duration=1)";                                // Croix extérieur
  x[7] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=square, motion=in, duration=1)";                               // Carré intérieur
  x[8] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=square, motion=out, duration=1)";                              // Carré extérieur
  x[9] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=star, motion=in, duration=1)";                                 // Etoile intérieur
  x[10] = "progid:DXImageTransform.Microsoft.Iris(irisStyle=star, motion=out, duration=1)";                               // Etoile extérieur
  x[11] = "progid:DXImageTransform.Microsoft.Wipe(GradientSize=.30, wipeStyle=0, motion=forward, duration=1)";            // Flou gauche-droite
  x[12] = "progid:DXImageTransform.Microsoft.Wipe(GradientSize=.30, wipeStyle=0, motion=reverse, duration=1)";            // Flou droite_gauche
  x[13] = "progid:DXImageTransform.Microsoft.Wipe(GradientSize=.30, wipeStyle=1, motion=forward, duration=1)";            // Flou haut-bas
  x[14] = "progid:DXImageTransform.Microsoft.Wipe(GradientSize=.30, wipeStyle=1, motion=reverse, duration=1)";            // Flou bas-haut
  x[15] = "progid:DXImageTransform.Microsoft.Fade(duration=1, overlap=1, center=0)";                                      // Fondu
  x[16] = "progid:DXImageTransform.Microsoft.Barn(orientation=horizontal, motion=out)";                                   // Rideau vertical exterieur
  x[17] = "progid:DXImageTransform.Microsoft.Barn(orientation=horizontal, motion=in)";                                    // Rideau vertical intérieur
  x[18] = "progid:DXImageTransform.Microsoft.Barn(orientation=vertical, motion=out)";                                     // Rideau horizontal exterieur
  x[19] = "progid:DXImageTransform.Microsoft.Barn(orientation=vertical, motion=in)";                                      // Rideau horizontal interieur
  x[20] = "progid:DXImageTransform.Microsoft.Blinds(bands=8,direction='RIGHT')";                                          // Volet vertical droite
  x[21] = "progid:DXImageTransform.Microsoft.Blinds(bands=8,direction='LEFT')";                                           // Volet verticla gauche
  x[22] = "progid:DXImageTransform.Microsoft.Blinds(bands=8,direction='UP')";                                             // Volet horizontal haut
  x[23] = "progid:DXImageTransform.Microsoft.Blinds(bands=8,direction='DOWN')";                                           // Volet horizontal bas
  x[24] = "progid:DXImageTransform.Microsoft.Checkerboard(squaresX=12,squaresY=8,direction='RIGHT',duration=1)";          // Damier droite
  x[25] = "progid:DXImageTransform.Microsoft.Checkerboard(squaresX=12,squaresY=8,direction='LEFT',duration=1)";           // Damier gauche
  x[26] = "progid:DXImageTransform.Microsoft.Checkerboard(squaresX=12,squaresY=8,direction='UP',duration=1)";             // Damier haut
  x[27] = "progid:DXImageTransform.Microsoft.Checkerboard(squaresX=12,squaresY=8,direction='DOWN',duration=1)";           // Damier bas
  x[28] = "progid:DXImageTransform.Microsoft.Inset( )";                                                                   // Diagonale haut-bas
  x[29] = "progid:DXImageTransform.Microsoft.Pixelate(MaxSquare=5,Duration=1,Enabled=false)";                             // Fondu pixelisé
  x[30] = "progid:DXImageTransform.Microsoft.RadialWipe(wipeStyle='clock')";                                              // Horloge
  x[31] = "progid:DXImageTransform.Microsoft.RadialWipe(wipeStyle='wedge')";                                              // Horloge double
  x[32] = "progid:DXImageTransform.Microsoft.RadialWipe(wipeStyle='radial')";                                             // Radial
  x[33] = "progid:DXImageTransform.Microsoft.RandomBars(orientation='horizontal')";                                       // Lignes horizontales
  x[34] = "progid:DXImageTransform.Microsoft.RandomBars(orientation='vertical')";                                         // Lignes verticales
  x[35] = "progid:DXImageTransform.Microsoft.Slide(slideStyle='HIDE', bands=1)";                                          // Glissement à gauche
  x[36] = "progid:DXImageTransform.Microsoft.Slide(slideStyle='PUSH', bands=1)";                                          // Pousser à gauche
  x[37] = "progid:DXImageTransform.Microsoft.Slide(slideStyle='SWAP', bands=1)";                                          // Pousser à gauche 2
  x[38] = "progid:DXImageTransform.Microsoft.Slide(slideStyle='HIDE', bands=7)";                                          // Lames horizontales
  x[39] = "progid:DXImageTransform.Microsoft.Slide(slideStyle='PUSH', bands=9)";                                          // lames horizontales 2
  x[40] = "progid:DXImageTransform.Microsoft.Slide(slideStyle='SWAP', bands=20)";
  x[41] = "progid:DXImageTransform.Microsoft.Spiral(GridSizeX=8, GridSizeY=8)";                                           // Spirale
  x[42] = "progid:DXImageTransform.Microsoft.Spiral(GridSizeX=64, GridSizeY=64)";                                         // Implosion
  x[43] = "progid:DXImageTransform.Microsoft.Stretch(stretchStyle='hide')";                                               // Déroulé gauche droite
  x[44] = "progid:DXImageTransform.Microsoft.Stretch(stretchStyle='spin')";                                               // Déroulé du centre
  x[45] = "progid:DXImageTransform.Microsoft.Stretch(stretchStyle='push')";                                               // Cube
  x[46] = "progid:DXImageTransform.Microsoft.Strips(Duration=1, Motion='leftdown')";                                      // Diagonale droite-gauche du haut
  x[47] = "progid:DXImageTransform.Microsoft.Strips(Duration=1, Motion='leftup')";                                        // Diagonale droite_gauche du bas
  x[48] = "progid:DXImageTransform.Microsoft.Strips(Duration=1, Motion='rightdown')";                                     // Diagonale gauche-droite du haut
  x[49] = "progid:DXImageTransform.Microsoft.Strips(Duration=1, Motion='rightup')";                                       // Diagonale gauche-droite du bas
  x[50] = "progid:DXImageTransform.Microsoft.Wheel(duration=1,spokes=2)";                                                 // Rotation centrée 1
  x[51] = "progid:DXImageTransform.Microsoft.Wheel(duration=1,spokes=4)";                                                 // Rotation centrée 2
  x[52] = "progid:DXImageTransform.Microsoft.Wheel(duration=1,spokes=10)";                                                // Rotation centrée 3
  x[53] = "progid:DXImageTransform.Microsoft.Wheel(duration=1,spokes=20)";                                                // Rotation centrée 4
  x[54] = "progid:DXImageTransform.Microsoft.zigzag(GridSizeX=8, GridSizeY=8)";                                         	// Zig-zag haut bas

//---
function getTopPos(inputObj) {		
	var returnValue = inputObj.offsetTop;
 	while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetTop;
 	return returnValue;
}

function getLeftPos(inputObj) {
	var returnValue = inputObj.offsetLeft;
	while((inputObj = inputObj.offsetParent) != null)returnValue += inputObj.offsetLeft;
	return returnValue;
}

//--- Afficher l'image
function showPreview(newSrc,xtrans) {
	if(!previewImage){
  	var images = document.getElementById('previewPane').getElementsByTagName('IMG');
  	if(images.length>0){
    	previewImage = images[0];
  	}else{
    	previewImage = document.createElement('IMG');
    	document.getElementById('previewPane').appendChild(previewImage);
  	}
	}
	if (document.all) {
		previewPane.style.filter=x[xtrans];
		previewPane.filters[0].Apply();
		previewImage.src = newSrc;
		previewPane.filters[0].Play();
	} else {
		previewImage.src = newSrc;
	}

	//--- Récupération du chemin
	var fileAndPath = document.getElementById('previewPane').appendChild(previewImage).src;
	//--- Recherche le dernier "/"
	var lastPathDelimiter = fileAndPath.lastIndexOf("/");
	//--- Récupération du nom du fichier
	var fileNameOnly = fileAndPath.substring(lastPathDelimiter+1);
	//--- Affiche le titre et la légende de l'image
	var i=0;
	for(i=0; i < comment_images.length; i++){
  	if(comment_images[i][0]==fileNameOnly) {
    	document.getElementById('legende').innerHTML=comment_images[i][1];
    	document.getElementById('titre_photo').innerHTML=comment_images[i][2];
    	//document.getElementById('photo').img.src=newSrc;

    	break;
  	}
	}
}

//--- Initialisation
function initSlide(e) {
	if(document.all)e = event;
	if(this.src.indexOf('over')<0)this.src = this.src.replace('.png','-over.png');
	slideSpeed = e.clientY + Math.max(document.body.scrollTop,document.documentElement.scrollTop) - getTopPos(this);
	if(this.src.indexOf('down')>=0){
  	slideSpeed = (slideSpeed)*-1;
	}else{
  	slideSpeed = arrowImageHeight - slideSpeed;
	}
	slideSpeed = Math.round(slideSpeed * 10 / arrowImageHeight);
}

//--- Arrêt du diaporama
function stopSlide() {
	slideSpeed = 0;
	this.src = this.src.replace('-over','');
}

//--- Gestion de la zone Image
function slidePreviewPane() {
	if(slideSpeed!=0){
  	var topPos = previewImagePane.style.top.replace(/[^\-0-9]/g,'')/1;
		if(slideSpeed<0 && slideEndMarker.offsetTop<(previewImageParent.offsetHeight - topPos)){
    	slideSpeed=0;
		}
		topPos = topPos + slideSpeed;
		if(topPos>0)topPos=0;
 		previewImagePane.style.top = topPos + 'px';
	}
	setTimeout('slidePreviewPane()',30);
}

//--- Clarifier la vignette
function revealThumbnail() {
	this.style.filter = 'alpha(opacity=100)';
	this.style.opacity = 1;
}

//--- Opacifier la vignette
function hideThumbnail() {
  this.style.filter = 'alpha(opacity=50)';
  this.style.opacity = 0.5;
}

//--- Initialisation du scroller des vignettes
function initGalleryScript() {

	//--- Récupérer la couche parente 'theImages'
	previewImageParent = document.getElementById('theImages');

	//--- Récupérer la balise 'div' 0 dans la couche
	previewImagePane = document.getElementById('theImages').getElementsByTagName('div')[0];

	//--- Le style de la balise Div est à 0px
	previewImagePane.style.top = '0px';

	//--- Récupérer l'ID 'galleryContainer'
	galleryContainer  = document.getElementById('galleryContainer');

	//--- Récupérer la balise 'img'
	var images = previewImagePane.getElementsByTagName('img');

	//--- Evénements sur la vignette
	for(var no=0;no<images.length;no++){
  	images[no].onmouseover = revealThumbnail;
  	images[no].onmouseout = hideThumbnail;
	}
	
	//--- Définition du marqueur de fin de slide
	slideEndMarker = document.getElementById('slideEnd');
	
	//--- Evènements sur les flèches
	document.getElementById('arrow_up_image').onmousemove = initSlide;
	document.getElementById('arrow_up_image').onmouseout = stopSlide;
	document.getElementById('arrow_down_image').onmousemove = initSlide;
	document.getElementById('arrow_down_image').onmouseout = stopSlide;

	//--- Gestion de l'image
	slidePreviewPane();
}

//--- Initialisation
window.onload = initGalleryScript;
