var fmcEquipe = new Class({
	options: {
		container:'container',
		listClass:'equipe-membre',
		thumbsContainerId:'equipe-liste',
		newInfo:0
	},
	initialize: function(options){
		this.setOptions(options);
		this.list = $$('.'+this.options.listClass);
		this.newInfo = this.options.newInfo;
		this.makeInfosArray();
		this.createBaseContainer();
		this.createThumbs();
		$('equipe_container').setStyle('display', 'none');
		this.showMe(this.newInfo);
		$('container').setStyle('height','auto');
	},
	makeInfosArray: function()
	{
		this.infos = [];
		this.list.each(function(el, id)
		{
			var tab = {
				id:id,
				titre:el.getChildren()[0].getText(),
				nom:el.getChildren()[1].getText(),
				img:{
					src:el.getChildren()[2].getFirst().getProperty('src'),
					width:el.getChildren()[2].getFirst().getProperty('width'),
					height:el.getChildren()[2].getFirst().getProperty('height')
				},
				tPForts:el.getChildren()[3].getChildren()[0].getText(),
				PForts:el.getChildren()[3].getChildren()[1].getText(),
				tAime:el.getChildren()[3].getChildren()[2].getText(),
				Aime:el.getChildren()[3].getChildren()[3].getText(),
				tExp:el.getChildren()[4].getChildren()[0].getText(),
				Exp:el.getChildren()[4].getChildren()[1].getText(),
				vignette:el.getChildren()[5].getFirst().getProperty('src')
			};
			//alert(el.vignette);
			this.infos.push(tab);
		}, this);
	},
	createBaseContainer: function()
	{
		var obj = this;
		this.container = new Element('div',{'class':'equipe-membre'}).injectTop($(this.options.container));
		this.titre = new Element('h1',{'styles':{'opacity':1}}).setHTML('&nbsp;').injectInside(this.container);
		this.titre.fx = new Fx.Styles(this.titre, {
			duration:500, 
			wait:false,
			onComplete: function()
			{
				if(obj.titre.getStyle('opacity')==0)
				{
					obj.titre.setHTML(obj.infos[obj.newInfo].titre);
					obj.titre.fx.start({'opacity':1});
				}
			}
		});
		this.nom = new Element('h6', {'class':'equipe', 'styles':{'opacity':1}}).injectInside(this.container);
		this.nom.fx = new Fx.Styles(this.nom, {
			duration:500, 
			wait:false,
			onComplete: function()
			{
				if(obj.nom.getStyle('opacity')==0)
				{
					obj.nom.setHTML(obj.infos[obj.newInfo].nom);
					obj.nom.fx.start({'opacity':1});
				}
			}
		});
		this.imgContainer = new Element('div', {'class':'equipe-image', 'styles':{'opacity':1}}).injectInside(this.container);
		this.imgContainer.fx = new Fx.Styles(this.imgContainer, {
			duration:500, 
			wait:false,
			onComplete: function()
			{
				if(obj.imgContainer.getStyle('opacity')==0)
				{
					obj.img.setProperties({'src':obj.infos[obj.newInfo].img.src, 'width':obj.infos[obj.newInfo].img.width,'height':obj.infos[obj.newInfo].img.height});
					obj.imgContainer.fx.start({'opacity':1});
				}
			}
		});
		this.img = new Element('img', {'src':'', 'alt':''}).injectInside(this.imgContainer);
		this.contenu = new Element('div', {'class':'equipe-contenu'}).injectInside(this.container);
		this.contenuExp = new Element('div', {'class':'contenu-experience'}).injectInside(this.container);
		this.ExperienceTitre = new Element('h2').setHTML('&nbsp;').injectInside(this.contenuExp);
			this.ExperienceTitre.fx = new Fx.Slide(this.ExperienceTitre, 
			{
				'mode':'horizontal',
				'onComplete':function()
				{
					if(obj.ExperienceTitre.fx.open==true)
					{
						obj.ExperienceTitre.setHTML(obj.infos[obj.newInfo].tExp);
						obj.ExperienceTitre.fx.slideIn();
					}
				}
			});
		this.Experience = new Element('div').injectInside(this.contenuExp);
			this.Experience.fx = new Fx.Slide(this.Experience, 
			{
				'mode':'horizontal',
				'onComplete':function()
				{
					if(obj.Experience.fx.open==true)
					{
						obj.Experience.setHTML(obj.infos[obj.newInfo].Exp);
						obj.Experience.fx.slideIn();
					}
				}
			});
		this.pointsFortsTitre = new Element('h2').setHTML('&nbsp;').injectInside(this.contenu);
			this.pointsFortsTitre.fx = new Fx.Slide(this.pointsFortsTitre, 
			{
				'mode':'horizontal',
				'onComplete':function()
				{
					if(obj.pointsFortsTitre.fx.open==true)
					{
						obj.pointsFortsTitre.setHTML(obj.infos[obj.newInfo].tPForts);
						obj.pointsFortsTitre.fx.slideIn();
					}
				}
			});
		this.pointsForts = new Element('div').injectInside(this.contenu);
			this.pointsForts.fx = new Fx.Slide(this.pointsForts, 
			{
				'mode':'horizontal',
				'onComplete':function()
				{
					if(obj.pointsForts.fx.open==true)
					{
						obj.pointsForts.setHTML(obj.infos[obj.newInfo].PForts);
						obj.pointsForts.fx.slideIn();
					}
				}
			});
		this.aimeTitre = new Element('h2').injectInside(this.contenu);
			this.aimeTitre.fx = new Fx.Slide(this.aimeTitre, 
			{
				'mode':'horizontal',
				'onComplete':function()
				{
					if(obj.aimeTitre.fx.open==true)
					{
						obj.aimeTitre.setHTML(obj.infos[obj.newInfo].tAime);
						obj.aimeTitre.fx.slideIn();
					}
				}
			});
		this.aime = new Element('div').injectInside(this.contenu);
			this.aime.fx = new Fx.Slide(this.aime, 
			{
				'mode':'horizontal',
				'onComplete':function()
				{
					if(obj.aime.fx.open==true)
					{
						obj.aime.setHTML(obj.infos[obj.newInfo].Aime);
						obj.aime.fx.slideIn();
					}
				}
			});
	},
	createThumbs: function()
	{
		var c = $(this.options.thumbsContainerId);
		obj = this;
		this.infos.each(function(el, id)
		{
			var thumb = new Element('img', {'alt':el.nom, 'src':el.vignette}).injectInside(
			new Element('a', 
				{
					'href':'#',
					'events':{
						'click':function(e)
						{
							var e = new Event(e);
							if(obj.newInfo != this.id)
							{
								obj.newInfo = id;
								obj.showMe(id);
							}
							e.stop();
							this.blur();
						}
					}
				}
			).injectInside(c));
			thumb.getParent().id = id;
		}, this);
	},
	showMe: function(id)
	{
		this.titre.fx.start({'opacity':0});//.setHTML(this.infos[id].titre);
		this.nom.fx.start({'opacity':0});//setHTML(this.infos[id].nom);
		this.imgContainer.fx.start({'opacity':0});
		this.pointsFortsTitre.fx.slideOut.delay(100, this.pointsFortsTitre.fx);
		this.pointsForts.fx.slideOut.delay(400, this.pointsForts.fx);//setHTML(this.infos[id].PForts);
		this.aimeTitre.fx.slideOut.delay(800, this.aimeTitre.fx);//setHTML(this.infos[id].tAime);
		this.aime.fx.slideOut.delay(1000, this.aime.fx);//setHTML(this.infos[id].tAime);
		this.ExperienceTitre.fx.slideOut.delay(1400, this.ExperienceTitre.fx);//setHTML(this.infos[id].ExpTitre);
		this.Experience.fx.slideOut.delay(1600, this.Experience.fx);//setHTML(this.infos[id].Exp);
		//alert('showMe '+id);
	},
	elementTransition: function(element, transition)
	{
		switch (transition)
		{
			case 'alpha':
				element.fx.start({'alpha':0});
				break;
			//{mode: 'horizontal'}
		}
	}
});
fmcEquipe.implement(new Options, new Events);

window.addEvent('domready', function(){
	/*	slide show demo	*/
	/*new fmcSlideshow({
		slides: $$('#realisations .real .real-images ul li')
	});*/
	var equipe = new fmcEquipe(
	{
		container:'right'
	});
	// !!!!!!!!!!!!!!!!!!!!!!!!!! json test  : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/*	var flashvars = {};
	flashvars.theText = Json.toString(Json.toString(equipe.infos));
	var params = {};
	params.menu = "false";
	//params.wmode = "transparent";
//	swfobject.embedSWF("flash/test.swf", "left", "250", "500", "9.0.0","js/expressInstall.swf", flashvars, params);
	$('left').innerHTML = Json.toString(Json.toString(equipe.infos));*/
});

