function AnimationAccueil()
{
	this.init = function(sContainerId, sClassItem,sListeImageNavigationId,sListeLienNavigationId,aListePhotosArticles,sUrlLecteur)
	{
		// Attributs du composant
		this.iNbVignetteVisible = 4;																			// le nombre de vignette affichée
		this.oContainerArticle = $(sContainerId);                 												// Le bloc contenant le corps des articles
		this.aListeItems = this.oContainerArticle.select('.' + sClassItem);										// La liste des articles affichables
		this.oBlocVignette = $(sListeImageNavigationId);														// Le bloc de navigation des vignettes
		this.sUrlLecteur = sUrlLecteur;																			// L'url du js pour le player video
		this.oBlocLienNavigation = $(sListeLienNavigationId);													// Le bloc contenant les liens de navigation (précédent / suivant ...)
		this.aListePhotos = aListePhotosArticles;																// La liste des photos présentes dans le corps des articles
		this.iScrollingStep = this.oBlocVignette.firstDescendant().offsetWidth * this.iNbVignetteVisible;		// La taille du bloc a afficher (taille d'une vignette * le nombre de vignette affichée)
		this.iDuration = 0.2 * this.iScrollingStep / 100;														// la durée de l'animation de scroll
		this.genererNavigation();																				// On génère directement les images 
	}
	
	/**
	 * Permet de retourner le nombre d'articles affichés (utile par exemple pour les filtres par thématique)
	 */
	this.getListe = function(sClassArticle){
		var aListeArticles;
		if (sClassArticle){
			aListeArticles = this.oContainerArticle.select('.' + sClassArticle);
		} else {
			aListeArticles = this.aListeItems;
		}
		return aListeArticles;
	}

	this.setFocus = function(eItem){
		if (eItem){
			eItem.up().select(".focus").each(function(element) {
				element.removeClassName("focus");
			});
			eItem.addClassName("focus");
		}
	}
	/**
	 * Génère le bloc de navigation c'est à dire : 
	 * - Affiche les 4 vignettes, 
	 * - génère les liens pour naviguer dans les vignettes, 
	 * - affiche le premier article si il y en a un
	 */
	this.genererNavigation = function(sClassArticle,eItem){
		this.setFocus(eItem);
		var aListeArticles = this.getListe(sClassArticle);
		
		this.afficherVignettes(aListeArticles);
		
		this.genererLienNavigation(aListeArticles);
		
		if (aListeArticles[0]){
			this.showArticle(aListeArticles[0].id);
		}
	}

	/**
	 * Permet d'afficher les vignettes par rapport aux articles disponibles
	 */
	this.afficherVignettes = function(aListeArticles){
		this.oBlocVignette.style.left='0px';
		var iNbActuVisible = 0;
		if (aListeArticles.length == this.aListeItems.length){
			this.oBlocVignette.select('li').each(function(element, index) {
				element.show();
				iNbActuVisible++;
			});
		} else {
			this.oBlocVignette.select('li').each(function(element, index) {
				element.hide();
			});
			for (var i=0; i<aListeArticles.length; i++){
				var element = $('v_' + aListeArticles[i].id);
				element.show();
				iNbActuVisible++;
			}
		}
		//Suivant le nombre de vignette affiché, la taille du bloc les contenant change
		this.oBlocVignette.setStyle({width: ((this.iScrollingStep)*iNbActuVisible/4) + 'px'});
	}

	/**
	 * Génère les liens de navigation (précédent /1,2,3.../ suivant ).
	 * Si il n'y a pas 4 articles à afficher on ne génère aucun lien.
	 */
	this.genererLienNavigation = function(aListeArticles){
		while (this.oBlocLienNavigation.hasChildNodes()) {
			this.oBlocLienNavigation.removeChild(this.oBlocLienNavigation.firstChild);
		}
		if (aListeArticles.length > this.iNbVignetteVisible){
			var eLiNavigation = new Element("li");
			var eLienNav = new Element("a", {href: "#", id: "precedent"}).update("&lt; pr&eacute;c&eacute;dente");
			eLienNav.observe('click',function(ev){animAccueil.GoBack();Event.stop(ev);});
			eLiNavigation.appendChild(eLienNav);
			this.oBlocLienNavigation.appendChild(eLiNavigation);
			
			for (var i = 0; i < aListeArticles.length / 4 ;i++){
				eLiNavigation = new Element("li");
				eLienNav = new Element("a", {href: "#"}).update((i+1));
				this.setOnClickPosition(i, eLienNav);
				if (i==0){
					eLiNavigation.addClassName("focus");
				}
				eLiNavigation.appendChild(eLienNav);
				this.oBlocLienNavigation.appendChild(eLiNavigation);
			}
			eLiNavigation = new Element('li');
			eLienNav = new Element("a", {href: "#", id: "suivant"}).update("suivante &gt;");
			eLienNav.observe('click',function(ev){animAccueil.GoForward();Event.stop(ev);});
			eLiNavigation.appendChild(eLienNav);
			this.oBlocLienNavigation.appendChild(eLiNavigation);
		}
	}
	
	//Pour IE 6 et 7
	this.setOnClickPosition = function(i, eLienNavigation){
		eLienNavigation.observe('click',function(ev){animAccueil.goToPosition(i,$(this).up());Event.stop(ev);});
	}

	/**
	 * Affiche l'article sélectionné et cache les autres.
	 */
	this.showArticle = function(sIdArticle){
		this.setFocus($("v_"+sIdArticle));
		var animA = this;
		this.aListeItems.each(function(eItem, index) {
			var aArticleVisuel = eItem.select('.article_visuel');
			if (eItem.id == sIdArticle){
				eItem.show();
				var url = animA.aListePhotos[eItem.id];
				//Si le visuel n'est pas créé, on l'ajoute. C'est soit une image, soit une vidéo.
				if (aArticleVisuel.length == 0){
					if (eItem.getElementsByTagName("img").length == 0 &&  url.indexOf(".flv")==-1){
						var photoArticle = new Element("img", {src: url, "class": "article_visuel", alt:"",width:"610px"});
						eItem.appendChild(photoArticle);
					} else if ( url.indexOf(".flv")!=-1){
						var ePContainer = new Element("p", {"class":"article_visuel video_accueil","id":"mpl"+index});
						eItem.appendChild(ePContainer);
						var lecteurvideo = new SWFObject(animA.sUrlLecteur,url +index,"605","329","7");
						lecteurvideo.addParam("allowfullscreen","true");
						lecteurvideo.addVariable("file",url);
						lecteurvideo.addVariable("image",url.substr(0,url.length-3) + 'jpg');
						lecteurvideo.addVariable("width","605");
						lecteurvideo.addVariable("displayheight","329");
						lecteurvideo.addVariable("height","329");
						lecteurvideo.write("mpl" + index);
					}
				}
			} else {
				eItem.hide();
				//IE continue de jouer la vidéo quand on la cache, j'ai pas trouvé d'autres méthode pour lui dire de stoper la video et son chargement...
				var aVideos = eItem.select(".video_accueil");
				for (var i = 0 ; i < aVideos.length ; i++) {
					aVideos[i].remove();
				}
			}
		});
	}

	/**
	 * Permet de faire un effet de slide horizontal de "iScrollingStep" pixels
	 */
	this.Move = function(iScrollingStep)
	{
		new Effect.Move(this.oBlocVignette, { x: iScrollingStep, 
											duration: this.iDuration, 
											transition: Effect.Transitions.linear,
											queue: { position: 'end', scope: 'global', limit: 1 }
											}
		);
	}
	

	/**
	 * Déplace les vignettes de la position courante à la position choisie
	 */
	this.goToPosition = function(iPosition,eItem)
	{
		this.setFocus(eItem);
		//on récupère la possition actuelle
		var iCurrentPosition = Math.round(Math.abs(this.oBlocVignette.positionedOffset().left / this.iScrollingStep));
		this.Move((Math.abs(iCurrentPosition) - iPosition) * this.iScrollingStep);
	}
	
	/**
	 * Déplace les vignettes de la position courante à la position suivante
	 */
	this.GoForward = function()
	{
		if (this.oBlocVignette.positionedOffset().left - this.iScrollingStep> -this.oBlocVignette.getWidth()) {
			//on récupère la possition actuelle pour mettre le focus 
			var iCurrentPosition = Math.round(Math.abs(this.oBlocVignette.positionedOffset().left / this.iScrollingStep));
			this.setFocus(this.oBlocLienNavigation.childElements()[iCurrentPosition+2]);
			this.Move(- this.iScrollingStep);
		}
	}

	/**
	 * Déplace les vignettes de la position courante à la position précédente
	 */
	this.GoBack = function()
	{
		if (this.oBlocVignette.positionedOffset().left < 0 ) {
			//on récupère la possition actuelle pour mettre le focus 
			var iCurrentPosition = Math.round(Math.abs(this.oBlocVignette.positionedOffset().left / this.iScrollingStep));
			this.setFocus(this.oBlocLienNavigation.childElements()[iCurrentPosition]);
			this.Move(this.iScrollingStep);
		}
	}
}

