// photo.js

// diaporama
var imgCpt = 1;
var timeoutID;



// - - - - - - - - - - - - - - - 

// variables globales

// menu
var photo_menu;

// liste des liens a du menu
var aliens;

// affichage photo
var photo_display;

// grande photo
var photo_img;

// titre photo
var titre_photo;

// lien photo
var lien_photo;

// variable pour lien vers image grandeur nature
var image_path;
var str_array;

// diaporama

function ChangeHref() {
	newlink( aliens[imgCpt] );
	imgCpt = imgCpt + 1;
	if (imgCpt == aliens.length) {
		imgCpt = 0;
	};
}

function newlink(a) 
{
	// si appelé sans paramètre
	// utiliser this

	if (typeof a == "undefined") { 
		// Pour IE
		a = this; 
	} else {
		// Pour Firefox
		if (a.href == undefined) a = this;
	}

	str_array=a.href.split('/');
	image_path="./maxi/"+str_array[str_array.length-1];
	lien_photo.href=image_path;
	// alert( a.href );
	photo_img.src = a.href;
	photo_img.alt = a.title;
	titre_photo.firstChild.nodeValue = a.title;
	return false;
}	

function slide(n)
{	
	clearInterval(timeoutID);
	if (n == 0) return;
	
	delay = n * 1000
	// delai en millisecondes
	timeoutID = setInterval("ChangeHref()", delay);
}

// Création du DIV diaporama à la volée 
// en utilisant les APIs DOM


function createDIV() {
	if (document.getElementById && document.createElement) 
	{
		myDocumentElements=document.getElementsByTagName("body");
		myBody=myDocumentElements.item(0);
		
		footerDIV = document.getElementById("footer");
		
		// création nouveau DIV
		diaporamaDIV = document.createElement("div");
		diaporamaDIV.setAttribute("id", "diaporama");

		// création nouveau paragraphe
		myP = document.createElement("p");
		
		// création nouveau texte
		myText = document.createTextNode("Diaporama ");
		
		// ajout dans le paragraphe
		myP.appendChild(myText);

		// création du lien a = 1
		myLink = document.createElement("a");
		myLink.setAttribute("href","javascript:slide(1);");
		myText = document.createTextNode("1 ");
		myLink.appendChild(myText);
		myP.appendChild(myLink);

		// création de nodes d'espacement
		myP.appendChild(document.createTextNode("\u00a0\u00a0"));

		// création du lien a = 2
		myLink = document.createElement("a");
		myLink.setAttribute("href","javascript:slide(2);");
		myText = document.createTextNode("2 ");
		myLink.appendChild(myText);
		myP.appendChild(myLink);
		
		// création de nodes d'espacement
		myP.appendChild(document.createTextNode("\u00a0\u00a0"));


		// création du lien a = 3
		myLink = document.createElement("a");
		myLink.setAttribute("href","javascript:slide(3);");
		myText = document.createTextNode("3 ");
		myLink.appendChild(myText);
		myP.appendChild(myLink);
		
		// création de nodes d'espacement
		myP.appendChild(document.createTextNode("\u00a0\u00a0"));

		// création nouveau texte
		myText = document.createTextNode("sec ");
		myP.appendChild(myText);
		
		// création de nodes d'espacement
		myP.appendChild(document.createTextNode("\u00a0\u00a0"));

		// création du lien a = stop
		myLink = document.createElement("a");
		myLink.setAttribute("href","javascript:slide(0);");
		myText = document.createTextNode("stop");
		myLink.appendChild(myText);
		myP.appendChild(myLink);

		// ajout du paragraphe dans le DIV
		diaporamaDIV.appendChild(myP);
		
		// insertion du DIV avant le footer
		myBody.insertBefore(diaporamaDIV, footerDIV);
	}
}


// diaporama : fin

function photoShow()
{
	// menu
	photo_menu = document.getElementById('menu') ;
	
	// liste des liens a du menu
	aliens = photo_menu.getElementsByTagName('a') ;
	
	// affichage photo
	photo_display = document.getElementById('photo') ;
	
	// grande photo
	photo_img = photo_display.getElementsByTagName('img')[0] ;
	
	// titre photo
	titre_photo = photo_display.getElementsByTagName('p')[0];
	
	// lien photo
	lien_photo = photo_display.getElementsByTagName('a')[0];
	
	// variable pour lien vers image grandeur nature
	image_path;
	str_array;
	
	// modifie le lien photo
	lien_photo.onclick = function()
	{
		window.open(this.href, 'Photo', 'toolbar=no, menubar=yes, location=no, resizable=yes, scrollbars=no, status=no'); 
		return false;
	}
	
	for(var i = 0 ; i < aliens.length ; i++)
	// pour tous les liens
	{
		aliens[i].onclick = newlink ;
	}
	
	createDIV();
}

// activation au chargement de la page
window.onload = photoShow ;

