var Glider = Class.create({
	
	initialize: function(classContents)
	{
		var obj              = this;
		this.contents 		 = $$('.'+classContents);
		this.currentItem		 = 0;
		/**
		 * Éléments à renseigner
		 */
		this.lien			 = $$('#gliderNav .infoGlider a')[0];		// l'objet étendu ($(monlien)) lien vers le détail
		this.image			 = $$('#glidercontent img')[0];				// l'objet image de l'apperçu
		this.label			 = $('titreProgrammeGlider');				// l'objet DOM contenant le titre de l'apperçu
		this.lienNext		 = $('gliderNext');							// lien vers l'apperçu suivant
		this.lienPrev		 = $('gliderPrev');							// lien vers l'apperçu précédent
		this.defaultSrc		 = 'modpub/modules/orientesud/images/interface/defaultProgramme.jpg';
		
		this.display();
		this.lienNext.observe('click',this.goNext.bind(this));
		this.lienPrev.observe('click',this.goPrev.bind(this));
	},
	
	display: function(){
		this.lien.href = this.contents[this.currentItem].select('a')[0];
		this.label.update(this.contents[this.currentItem].select('p')[0].firstChild.data);
		if(!Object.isUndefined(this.contents[this.currentItem].select('img')[0])){
			this.image.src = this.contents[this.currentItem].select('img')[0].src;
		}else{
			this.image.src = this.defaultSrc;
		}
		this.image.alt = this.contents[this.currentItem].select('p')[0].firstChild.data;
		this.image.title = this.contents[this.currentItem].select('p')[0].firstChild.data;
		this.label.up('div').setStyle('width:auto');
		
	},
	
	goNext: function(event){
		Event.stop(event);
		if(this.currentItem+1 > this.contents.length-1){
			this.currentItem = 0;
		}else{
			this.currentItem ++;
		}
		this.display();
	},
	
	goPrev: function(event){
		Event.stop(event);
		if(this.currentItem-1 < 0){
			this.currentItem = this.contents.length-1;
		}else{
			this.currentItem --;
		}
		this.display();
	}
	
});

Event.observe(window,'load',function()
{
	if($$('.programmeForGlider'))
	{
		new Glider('programmeForGlider');
	}
});

