// JavaScript Document


/*******************************************/
/* NOMS DES REPERTOIRES ET FICHIERS IMAGES */
/*******************************************/
var thePreviewDirectory = "Videos";                          /* Ne pas mettre de '/' a la fin */
var theVideoDirectory   = "http://www.essaisrff.net/videos"; /* Ne pas mettre de '/' a la fin */
var theGalleryPrefix    = "galerie_";
var thePreviewPrefix    = "vignette_";
var theVideoPrefix      = "video_";
var thePreviewExtension = ".jpg";
var theVideoExtension   = ".swf";

/*************************/
/* NOM DU CONTAINER HTML */
/*************************/
var theContainerIdPrefix = "video_";

/******************************************/
/* NOMBRE DE GALERIES ET GALERIE COURANTE */
/******************************************/
var theGalleryNumber     = 1;
var theGalleryIndex      = 1; /* Demarre a 1 */

/********************************************/
/* NOMBRE DE VIGNETTES ET VIGNETTE COURANTE */
/********************************************/
var theContainerNumber   = 5;
var theVideoIndex        = 1; /* Demarre a 1 */


/***********************/
/* TITRES DES GALERIES */
/***********************/
var theGalleryTitleArray =
new Array(
	/* GALERIE 1 =>*/ "Vidéos",
	/* GALERIE 2 =>*/	"Galerie 2"
);

var theVideoTitleArray = 
new Array(
	/* GALERIE 1 =>*/[
		/* VIDEO 1 => */ "LGV Est européenne au banc d'essai",
		/* VIDEO 2 => */ "Le train d'essai",
		/* VIDEO 3 => */ "Les essais de montée en vitesse",
		/* VIDEO 4 => */ "Voiture Mauzin",
		/* VIDEO 5 => */ "Interview avec Patrick Launay",
		/* VIDEO 6 => */ "Vidéo 6"
									  ],
	/* GALERIE 2 =>*/[
		/* VIDEO 1 => */ "Vidéo 1",
		/* VIDEO 2 => */ "Vidéo 2",
		/* VIDEO 3 => */ "Vidéo 3",
		/* VIDEO 4 => */ "Vidéo 4",
		/* VIDEO 5 => */ "Vidéo 5",
		/* VIDEO 6 => */ "Vidéo 6"
									  ]
);
	

/********************************************************
go_to_gallery : permet d'aller a la galerie precedente ou suivante

Entree:
	pWhichWay (int) : -1=vers l'arriere, 1=vers l'avant

Sortie:
	
********************************************************/
function go_to_gallery(pWhichWay)
{
	if (pWhichWay == -1)
	{
		theGalleryIndex--;
		if (theGalleryIndex < 1)
			theGalleryIndex = theGalleryNumber;
		theVideoIndex = 1;
		refresh_gallery();
	}
	else if(pWhichWay == 1)
	{
		theGalleryIndex++;
		if (theGalleryIndex > theGalleryNumber)
			theGalleryIndex = 1;
		theVideoIndex = 1;
		refresh_gallery();
	}
}

/********************************************************
go_to_image : permet de selectionner une video dans la galerie

Entree:
	pIndex (int) --> indice de la video selectionnee

Sortie:
	
********************************************************/
function go_to_image(pIndex)
{
	if (1 <= pIndex && pIndex <= theContainerNumber)
	{
		theVideoIndex = pIndex;
		refresh_gallery();
	}
}

/********************************************************
refresh_gallery : permet de mettre a jour l'ensemble {titre, vignettes, video)

Entree:
	

Sortie:
	
********************************************************/
function refresh_gallery()
{
	/* Rafraichit le titre de la galerie */
	load_gallery_title();
	
	/* Rafraichit les videos de la galerie */
	load_gallery_previews();
	
	/* Rafraichit la video associee a la vignette selectionnee */
	load_main_video();
}

/********************************************************
load_gallery_title : permet de mettre a jour le titre de la galerie

Entree:
	

Sortie:
	
********************************************************/
function load_gallery_title()
{
	var a_TD_Object = this.document.getElementById("titre_galerie");
	delete_all_children(a_TD_Object);
	var aTextNode = this.document.createTextNode(theGalleryTitleArray[theGalleryIndex-1]);
	a_TD_Object.appendChild(aTextNode);
}

/********************************************************
load_gallery_previews : permet de mettre a jour les vignettes de la galerie

Entree:
	

Sortie:
	
********************************************************/
function load_gallery_previews()
{
	for (var i = 1; i <= theContainerNumber; i++)
		load_preview(i);
}

/********************************************************
load_main_video : met a jour la video principale ainsi que le titre de la video

Entree:
	

Sortie:
	
********************************************************/
function load_main_video()
{
	var a_H2_Object = this.document.getElementById("titre_video_pour_js");
	delete_all_children(a_H2_Object);
	var aTextNode = this.document.createTextNode(theVideoTitleArray[theGalleryIndex-1][theVideoIndex-1]);
	a_H2_Object.appendChild(aTextNode);
	
	
	var aVideoSrc = theVideoDirectory + "/" + /*theGalleryPrefix + print_number(theGalleryIndex,2)
								+ "/" +*/ theVideoPrefix + print_number(theVideoIndex,2) + theVideoExtension;
								
	var aDivInnerHTML = 
'<object id="object_video_pour_js" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="318" height="238">' +
'	<param name="movie" value="' + aVideoSrc + '" />' +
'	<param name="quality" value="high" />' +
'	<embed name="object_video_pour_js" src="' + aVideoSrc + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="318" height="238"></embed>' +
'</object>';
	
	var a_DIV_Object = this.document.getElementById("div_video_pour_js");
	a_DIV_Object.innerHTML = aDivInnerHTML;
}

/********************************************************
load_preview : met a jour la vignette specifiee

Entree:
	pIndex (int) --> indice de la vignette

Sortie:
	
********************************************************/
function load_preview(pIndex)
{
	var a_TD_ContainerName = theContainerIdPrefix + print_number(pIndex,2);
	var a_TD_Container = this.document.getElementById(a_TD_ContainerName);
	delete_all_children(a_TD_Container);
	
	/* On veut obtenir l'équivalent de la ligne HTML suivante:
	<a href="#" onclick="go_to_image(xx)"><img alt="xx" src="xx" galleryimg="no" /></a> */
	if (pIndex != theVideoIndex)
	{
		var a_A_Object = this.document.createElement("a");
		a_A_Object.href = "#";
		a_A_Object.onclick = function() {go_to_image(pIndex);}
		a_TD_Container.appendChild(a_A_Object);
	
		var a_IMG_Object = this.document.createElement("img");
		a_IMG_Object.alt = theVideoTitleArray[theGalleryIndex-1][pIndex-1];
		a_IMG_Object.title = theVideoTitleArray[theGalleryIndex-1][pIndex-1];
		a_IMG_Object.src = thePreviewDirectory + "/" + theGalleryPrefix + print_number(theGalleryIndex,2)
										 + "/" + thePreviewPrefix + print_number(pIndex,2) + thePreviewExtension;
		a_IMG_Object.setAttribute("galleryimg", "no");
		a_A_Object.appendChild(a_IMG_Object);
	}
	else
	{
		var a_IMG_Object = this.document.createElement("img");
		a_IMG_Object.className = "courant";
		a_IMG_Object.alt = theVideoTitleArray[theGalleryIndex-1][pIndex-1];
		a_IMG_Object.title = theVideoTitleArray[theGalleryIndex-1][pIndex-1];
		a_IMG_Object.src = thePreviewDirectory + "/" + theGalleryPrefix + print_number(theGalleryIndex,2)
										 + "/" + thePreviewPrefix + print_number(pIndex,2) + thePreviewExtension;
		a_IMG_Object.setAttribute("galleryimg", "no");
		a_TD_Container.appendChild(a_IMG_Object);
	}
}

/********************************************************
print_number : convertit un entier positif vers une chaine de caracteres

Entree:
	pNumber (int) --> entier positif a convertir
	pDigitsNumber (int) --> nombre minimal de chiffres (left-zero-padding)

Sortie:
	
********************************************************/
function print_number(pNumber, pDigitsNumber)
{
	
	var aString = "";
	aString += pNumber;
	var aLength = aString.length;
	for (var i = 1; i <= pDigitsNumber-aLength; i++)
		aString = "0" + aString;
	return aString;
}

/********************************************************
delete_all_children : detruit tous les fils d'un objet HTML

Entree:
	pObject --> objet HTML specifie

Sortie:
	
********************************************************/
function delete_all_children(pObject)
{
	while (pObject.childNodes.length > 0)
		pObject.removeChild(pObject.childNodes[0]);
}
