var AccountLogin = new Class({
	Implements: [Options, Events, Log],
	Extends: Page,
	
	// Variables
	loginForm: null,
	noAccountForm: null,

	// Class instances


	initialize: function( name, element, options )
	{
		this.enableLog();
		//this.disableLog();
		this.log("AccountLogin::initialize(" + name + ", " + element + ", " + options + ")");

		// Invoke parent method
		this.parent( name, element, options );

		// Init forms
		this.initLoginForm();
	},

	/*
	 * Init login form
	 */
	initLoginForm: function()
	{
		this.log("AccountLogin::initLoginForm()");

		// Forgotten password
		this.forgottenPassword = this.element.getElement('.login .forgotten-password');
		this.forgottenPassword.fx = new Fx.Morph(this.forgottenPassword, {
			duration: 500,
			transition: Fx.Transitions.Quad.easeOut,
			link: 'cancel'
		});

		var options = {
			showLoader: true,
			allowStatus: true,
			formErrorMessage: {
				allow: true,
				container: this.element.getElement('.login .form-message-container'),
				allowClose: false
			}
		};

		var elementOptions = {
			hintText: 'naam@domein.nl'
		};

		var form = new Form($('account-login-form'), options);

		var emailElement = new FormElement(form, 'email', elementOptions);
		emailElement.addValidation(Form.REGEX_EMAIL, 'Vul je e-mail adres in');
		form.addElement(emailElement);

		var passwordElement = new FormElement(form, 'password', {});
		passwordElement.addValidation(Form.REGEX_PASSWORD, 'Vul je wachtwoord in');
		form.addElement(passwordElement);

		// Add buttons
		var submitButton = new FormSubmitButton(form, '.submit', {showLoader: true});
		form.addButton(submitButton);

		// Save form
		this.accountForm = form;

		this.accountForm.addEvent('onError', function() {

			if(passwordElement.validate() !== true)
			{
				this.forgottenPassword.fx.start({
					'background-color': '#ff6c00'
				});
			}
			else
			{
				this.forgottenPassword.fx.start({
					'background-color': '#595959'
				});
			}

		}.bind(this));
	}

});
