// JavaScript Document


function domready() {
	
	// Scrolling progressif
	new SmoothScroll({duration: 1500, transition: Fx.Transitions.sineInOut});
	
	// Realisations
	/*var rea = new Work($('prout0'));*/
	var elmWorks = $$('div.work');
	elmWorks.each(function(item, index) {
		new Work(item); 
	});
	
	// LightBox
	Lightbox.init({descriptions: '.lightboxDesc', showControls: true});
}


var Work = new Class({
	initialize: function(elm) {
		this.elm = elm;
		this.elmDetails = this.elm.getElement('div.details');
		this.mySlide = new Fx.Style(this.elmDetails, 'margin-top', {duration:500});
		this.state = false;
		this.slide();
		this.timer = null;
	},
	
	slide: function() {
		var self = this;
			
		this.elm.addEvent('mouseover', function(e) {
			e = new Event(e);
			self.toggle('on');
			e.stop();
		});
		this.elm.addEvent('mouseout', function(e) {
			e = new Event(e);
			self.toggle('off');
			e.stop();
		});
	},
	
	toggle: function(move) {		
		var self = this;
		
		if(move == "on") {
			$clear(this.timer);
			if(!this.state) {
				this.state = true;
				this.mySlide.stop();
				this.mySlide.start(this.elmDetails.getStyle('margin-top'), 40);
			}
		}
		
		if(move == "off") {
			function showOff() {
				if(self.state) {
					self.mySlide.stop();
					self.mySlide.start(self.elmDetails.getStyle('margin-top'), 140);
					self.state = false;
				}
			}
			this.timer = showOff.delay(200);
		}
	}
});

window.addEvent("domready", domready);

