window.addEvent('domready', function() {   
    
	// Logo
	$('logo').addEvents({
		'mouseover' : function(){
			$('logo').getElements('span').addClass('on');
		},
		'mouseout' : function() {
			$('logo').getElements('span').removeClass('on');
		} 
	});
	
	
	// Formulaire du header
	$('header').getElements('input[type=text],input[type=password]').addEvents({
		'focus' : function(){
			if (this.get('value') == this.defaultValue) {
				this.set('value', '');
				}
		},
		'blur' : function(){
			if (this.get('value') == '') {
				this.set('value', (this.defaultValue));
				}
		}
	});
	
	// Validation du formulaire
	if($('formConnexion')) {
		$('formConnexion').addEvent('submit', function(event) {
			var msg = $('connexionNotity');
			event.stop();
			var erreur = 0;
			if($('login_email').value=='email' || $('login_mdp').value=='Mot de passe') {
				erreur = 1;
				msg.addClass('on');
				msg.set('html','Veuillez saisir votre email et votre mot de passe.');
			}
			if(erreur == 1) {
				event.stop();
				return false;
			} else {
				$('formConnexion').submit();
			}
		});
	} // $('formConnexion')
	
	
});


/* scroll spy plugin / class */
var ScrollSpy = new Class({
	
	/* implements */
	Implements: [Options,Events],

	/* options */
	options: {
		min: 0,
		mode: 'vertical',
		max: 0,
		container: window,
		onEnter: $empty,
		onLeave: $empty,
		onTick: $empty
	},
	
	/* initialization */
	initialize: function(options) {
		/* set options */
		this.setOptions(options);
		this.container = $(this.options.container);
		this.enters = this.leaves = 0;
		this.max = this.options.max;
		
		/* fix max */
		if(this.max == 0) 
		{ 
			var ss = this.container.getScrollSize();
			this.options.max = this.options.mode == 'vertical' ? ss.y : ss.x;
		}
		/* make it happen */
		this.addListener();
	},
	
	/* a method that does whatever you want */
	addListener: function() {
		/* state trackers */
		this.inside = false;
		this.container.addEvent('scroll',function() {
			
			/* if it has reached the level */
			var position = this.container.getScroll();
			
			var xy = this.options.mode == 'vertical' ? position.y : position.x;
			/* if we reach the minimum and are still below the max... */
			if(xy >= this.options.min /*&& xy <= this.max*/) {
					/* trigger Enter event if necessary */
					if(!this.inside) {
						/* record as inside */
						this.inside = true;
						this.enters++;
						/* fire enter event */
						this.fireEvent('enter',[position,this.enters]);
					}
					/* trigger the "tick", always */
					this.fireEvent('tick',[position,this.inside,this.enters,this.leaves]);
			}
			else {
				/* trigger leave */
				if(this.inside) 
				{
					this.inside = false;
					this.leaves++;
					this.fireEvent('leave',[position,this.leaves]);
				}
			}
		}.bind(this));
	}
});


window.addEvent('domready',function() {
	new SmoothScroll({duration:500});
	$('gototop').set('opacity','0').setStyle('display','block');
	var ss = new ScrollSpy({
		min: 70,
		onEnter: function(position,state,enters) {
			$('gototop').fade('in');
		},
		onLeave: function(position,state,leaves) {
			$('gototop').fade('out');
		},
		container: window
	});
});
