var Profil = new Class({
	
	Implements: [Options, Events],
	options:{
		infos:null,
		parent:null,
		reduce:null,
		index:null,
		total:null
	},
	
	initialize:function(options) {
		this.setOptions(options);
		//debug('Profil:initialize');
		
		this.initContainer();
		
		this.initElements();
		
		this.initFx();
		
		this.initImage();
		
		this.initEvents();
	},
	
	initContainer:function() {
		this.container = new Element('li').inject(this.options.parent);
		
		this.container.setStyles({
			'width': parseInt(this.options.infos.image_width_mini),
			'height': parseInt(this.options.infos.image_height_mini),
			'position':'absolute',
			'left': this.options.left
		});
	},
	
	initElements:function() {
		this.cartel = new Element('div').inject(this.container);
		this.libelle = new Element('h3').inject(this.cartel);
		this.libelle.set('html', this.options.infos.libelle);
		this.accroche = new Element('p').inject(this.cartel);
		this.accroche.set('html', this.options.infos.accroche);
		
		this.cartel_fx = new Fx.Morph(this.cartel, {
			transition: Fx.Transitions.Quad.easeOut,
			link:'cancel',
			duration:300
		});
	},
	
	initFx:function() {
		this.cartel_fx_src = {
			opacity: 0,
			'top': parseInt(this.options.infos.image_height_mini)
		}
		
		this.cartel_fx_dest = {
			opacity: 1,
			'top': parseInt(this.options.infos.image_height_mini) + 6
		}
		
		this.cartel.setStyles({
			'display': 'block',
			'left': 0
		});
		this.cartel_fx.set(this.cartel_fx_src);
	},
	
	initImage:function() {
		this.image = new PictureMini({
			filename: this.options.infos.image,
			width: this.options.infos.image_width_mini,
			height: this.options.infos.image_height_mini,
			parent:this.container,
			reduce: this.options.reduce
		});
		this.image.target.setStyle('cursor','pointer');
	},
	
	initEvents:function() {
		this.bound_image_enter = this.enterImage.bind(this);
		this.bound_image_leave = this.leaveImage.bind(this);
		this.bound_image_click = this.clickImage.bind(this);
		
		this.add_events();
		
		this.bound_image_complete = this.imageComplete.bind(this);
		this.image.addEvent('closeComplete', this.bound_image_complete);
	},
	
	imageComplete:function() {
		this.fireEvent('imageComplete');
	},
	
	enterImage:function() {
		this.image.open();
		this.container.setStyle('z-index', 10000);
		this.cartel_fx.start(this.cartel_fx_dest);
	},
	
	leaveImage:function() {
		this.image.close();
		this.container.setStyle('z-index', 0);
		this.cartel_fx.start(this.cartel_fx_src);
	},
	
	clickImage:function() {
		this.leaveImage();
		this.fireEvent('deploy', {index: this.options.index});
		this.deploy();
	},
	
	deploy:function() {
		this.big = new Big({
			infos:this.options.infos,
			parent:$$('.text_wrapper')[0],
			index:this.options.index,
			total:this.options.total
		});
		this.big.addEvents({
			'close':function() {
				this.fireEvent('closeBig');
				this.image.addEvents({
					'mouseenter': this.bound_image_enter,
					'mouseleave': this.bound_image_leave,
					'click': this.bound_image_click
				});
				this.big = null;
			}.bind(this),
			'prev':function() {
				this.fireEvent('prevBig', {index: this.options.index});
			}.bind(this),
			'next':function() {
				this.fireEvent('nextBig', {index: this.options.index});
			}.bind(this)
		});
	},
	
	close:function() {
		if(this.big) this.big.fireEvent('close');
		this.image.init();
	},
	
	add_events:function() {
		this.image.addEvents({
			'mouseenter': this.bound_image_enter,
			'mouseleave': this.bound_image_leave,
			'click': this.bound_image_click
		});
	},
	
	remove_events:function() {
		this.image.removeEvents({
			'mouseenter': this.bound_image_enter,
			'mouseleave': this.bound_image_leave,
			'click': this.bound_image_click
		});
	}
		
});
