// Initialisation de toutes les fonctions
window.addEvent('domready', function(){
	light();
	gallery();
	formChecking();
});

var light = function(){
	$$('div.light a').removeEvents().addEvents({
		'mouseover': function(){
			this.getParent('div.light').getElement('p.on').fade(1);
		},
		'mouseout': function(){
			this.getParent('div.light').getElement('p.on').fade(0);
		}
	});
}

var gallery = function(){
	$$('div.realisation').each(function(el){
		var ul = el.getElement('ul');
		var globalW = el.getSize().x;
		var wrapW = el.getElement('li').getComputedSize().totalWidth * el.getElements('li').length;
		ul.setStyle('width', wrapW);
		
		var scroll = new Fx.Scroll(el,{
			link: 'cancel', 
			transition: 'linear',
			duration: 1000
		});
		scroll.set(0, 0);
		
		var side = false;
		document.removeEvents('mousemove').addEvent('mousemove', function(e){
			var box = (e.client.y > el.getCoordinates().top && e.client.y < el.getCoordinates().bottom) ? true : false;
			
			if(e.client.x > (globalW / 2) + 200 && (side == 1 || !side) && box){
				var speed = 1 - (el.getScroll().x / wrapW);
				scroll.options.duration = el.getElements('li').length * 1000 * speed;
				scroll.start(globalW, 0);
				side = 2;
			}
			else if(e.client.x < (globalW / 2) - 200 && (side == 2 || !side) && box){
				var speed = el.getScroll().x / wrapW;
				scroll.options.duration = el.getElements('li').length * 1000 * speed;
				scroll.start(0, 0);
				side = 1;
			}
			else if(e.client.x > (globalW / 2) - 200 && e.client.x < (globalW / 2) + 200 || !box){
				scroll.pause();
				side = false;
			}
		});
	});
}

var formChecking = function(){
	$$('form.check').each(function(el){
		new Form.Validator(el);
	});
}
