var MailingList = new Class({
	initialize: function(container){
		this.form = $(container);
		this.email = this.form.getElement('input.email');
		this.regExp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		this.error = $('error');
		this.start();
	},
	start: function(){
		var fx = new Fx.Style(this.error, 'opacity').set(0);
		this.form.addEvent('submit', function(e){
			if(this.email.value.search(this.regExp) == -1){
				new Event(e).stop();
				this.email.addClass('error');
				fx.start(0, 1);
			} else {
				new Event(e);
				this.email.removeClass('error');
				fx.start(1, 0);
			}
		}.bind(this));
		this.email.addEvent('keyup', function(){
			fx.set(0);
			if(this.email.value.search(this.regExp) != -1) this.email.removeClass('error');
		}.bind(this));
		this.error.addEvent('click', function(){
			fx.start(1, 0);
		});
	}
});

window.addEvent('domready', function(){
	new MailingList('mailing');
	new Nav('nav');
});