skriv.main = new function() {
	/**
	 * Envoie l'utilisateur vers l'application.
	 * @param	string	lang	Langue d'affichage.
	 */
	this.gotoApp = function(lang) {
		window.location.href = "http://app.skriv.org/" + lang;
	};
	/** Affiche les choix de login. */
	this.showLoginChoices = function() {
		this.resetLoginChoices();
		$("#login-choices").slideToggle("slow");
	};
	/** Remet à zéro l'affichage des choix de login. */
	this.resetLoginChoices = function() {
		// retour initial
		$("#login-info-google").hide();
		$("#login-info-twitter").hide();
		$("#login-info-openid").hide();
		$("#login-info-skriv").hide();
		$("#login-choices-recap").hide();
		$("#login-choice-google").show();
		$("#login-choice-twitter").show();
		$("#login-choice-openid").show();
		$("#login-choice-skriv").show();
	};
	/** Affiche l'identification Google. */
	this.showGoogleLogin = function() {
		this.resetLoginChoices();
		$("#login-choice-twitter").hide("drop", {direction: "down"}, 1000);
		$("#login-choice-openid").hide("drop", {direction: "down"}, 1000);
		$("#login-choice-skriv").hide("drop", {direction: "down"}, 1000);
		// affichage
		setTimeout(function() {
			$("#login-info-google").fadeIn("slow");
			// récap de choix
			$("#login-choice-google-mini").hide();
			$("#login-choice-twitter-mini").show();
			$("#login-choice-openid-mini").show();
			$("#login-choice-skriv-mini").show();
			setTimeout(function() {
				$("#login-choices-recap").fadeIn("slow");
			}, 500);
		}, 1200);
	};
	/** Affiche l'identification Twitter. */
	this.showTwitterLogin = function() {
		this.resetLoginChoices();
		$("#login-choice-google").hide("drop", {direction: "down"}, 1000);
		$("#login-choice-openid").hide("drop", {direction: "down"}, 1000);
		$("#login-choice-skriv").hide("drop", {direction: "down"}, 1000);
		// affichage
		setTimeout(function() {
			$("#login-info-twitter").fadeIn("slow");
			// récap de choix
			$("#login-choice-google-mini").show();
			$("#login-choice-twitter-mini").hide();
			$("#login-choice-openid-mini").show();
			$("#login-choice-skriv-mini").show();
			setTimeout(function() {
				$("#login-choices-recap").fadeIn("slow");
			}, 500);
		}, 1200);
	};
	/** Affiche l'identification OpenID. */
	this.showOpenIdLogin = function() {
		this.resetLoginChoices();
		$("#login-choice-google").hide("drop", {direction: "down"}, 1000);
		$("#login-choice-twitter").hide("drop", {direction: "down"}, 1000);
		$("#login-choice-skriv").hide("drop", {direction: "down"}, 1000);
		// affichage
		setTimeout(function() {
			$("#login-info-openid").fadeIn("slow");
			// récap de choix
			$("#login-choice-google-mini").show();
			$("#login-choice-twitter-mini").show();
			$("#login-choice-openid-mini").hide();
			$("#login-choice-skriv-mini").show();
			setTimeout(function() {
				$("#login-choices-recap").fadeIn("slow");
			}, 500);
			$("#edit-openid-url")[0].focus();
		}, 1200);
	};
	/** Affiche l'identification Skriv. */
	this.showSkrivLogin = function() {
		this.resetLoginChoices();
		$("#login-choice-google").hide("drop", {direction: "down"}, 1000);
		$("#login-choice-twitter").hide("drop", {direction: "down"}, 1000);
		$("#login-choice-openid").hide("drop", {direction: "down"}, 1000);
		// affichage
		setTimeout(function() {
			$("#login-info-skriv").fadeIn("slow");
			// récap de choix
			$("#login-choice-google-mini").show();
			$("#login-choice-twitter-mini").show();
			$("#login-choice-openid-mini").show();
			$("#login-choice-skriv-mini").hide();
			setTimeout(function() {
				$("#login-choices-recap").fadeIn("slow");
			}, 500);
			if ($("#edit-skriv-email")[0].value.length)
				$("#edit-skriv-pwd")[0].focus();
			else
				$("#edit-skriv-email")[0].focus();
		}, 1200);
	};
	/**
	 * Lance la création d'un compte par login/password.
	 * @param	string	lang	Langue de visualisation du site.
	 */
	this.skrivCreateAccount = function(lang) {
		$("#error-skriv-email").hide();
		$("#form-login-skriv")[0].action = "/" + lang + "/auth/skriv/create";
		var email = $("#edit-skriv-email")[0].value;
		if (!skriv.checkEmail(email))
			$("#error-skriv-email").show();
		else
			$("#form-login-skriv")[0].submit();
	};
	/**
	 *  Lance une authentification login/password.
	 *  @param	string	lang	Langue de visualisation du site.
	 */
	this.skrivLogin = function(lang) {
		$("#error-skriv-email").hide();
		$("#form-login-skriv")[0].action = "/" + lang + "/auth/skriv/id";
	};
	/** Vérifie l'adresse email du login Skriv. */
	this.checkEmailSkrivLogin = function() {
		var email = $("#edit-skriv-email")[0].value;
		if (!skriv.checkEmail(email)) {
			$("#error-skriv-email").show();
			return (false);
		}
		return (true);
	};
};

