/********************************************************************/
/*********************** Nicolas SIONNIERE **************************/
/******************** (c) 2010 SIONNIERE NICOLAS ********************/
/****************** Email: portfolio@sionniere.com ******************/
/****************** http://nicolas.sionniere.com/ *******************/
/********************************************************************/

$(document).ready(function(){

	$('#tabs').tabs();

	$('.error').hide();

	$('.boxgrid.captionfull').hover(function(){
	$('.cover').fadeTo(0,0.9)
	$(".cover", this).stop().animate({top:'0px'},{queue:false,duration:250});
	}, function() {
	$(".cover", this).stop().animate({top:'200px'},{queue:false,duration:500});
	});

	$('a[name=modal]').click(function(e) {
		e.preventDefault();
		$('#reponse').html('');
		$('html').animate({scrollTop:0}, "fast")
		var maskHeight = $(document).height();
		var maskWidth = $(document).width();
		$('#mask').css({'width':maskWidth,'height':maskHeight});
		$('#mask').fadeTo("fast",0.8);	
		var winH = $(window).height();
		var winW = $(window).width();
		$("#form").css('top',  winH/2-2*$("#form").height()/3);
		$("#form").css('left', winW/2-$("#form").width()/2);
		$("#form").fadeTo("slow",0.9); 
	});
	$('.window .close').click(function (e) {
		e.preventDefault();
		$('#mask').fadeOut('slow');
		$('.window').fadeOut('fast');
	});		
	$('#mask').click(function () {
		$(this).fadeOut('slow');
		$('.window').fadeOut('fast');
	});	
	$('<div id="wtf">☠</div>').appendTo('body');
	$('#wtf').click(function(e){
		if(e.ctrlKey){
			e.preventDefault(); 
			alert("Bravo ! Voici l'énigme :"+"\r\n"+"0x ou # → 687474703A2F2F6269742E6C792F73336372337473"+"\n\r"+'Indice : Fermer et faire "ALT+CLIC"');
		}else{
			if(e.altKey){
				alert("http://home2.paulschou.net/tools/xlate/");
			}
			else{
				alert('CTRL+CLIC');
			}
		}
	});
	$('#btnsend').click(function() {
		$('.error').hide();
		var email = $("input#email").val();
		var regexp = /^[a-z0-9._%-]+@[a-z0-9.-]+\.[a-z]{2,4}$/i;
		if (email.match(regexp)==null) {
			$("label#email_error").show();
			$("input#email").focus();
			return false;
		}
		var message = $("textarea").val();
		if (message == "") {
			$("label#message_error").show();
			$("input#message").focus();
			return false;
		}
		var dataString = 'email='+ email + '&message=' + message;
		$.ajax({
			type: "POST",
			url: "envoi-formulaire.html",
			data: dataString,
			success: function(data){
				if(data=="DONE"){
					$('#reponse').html('<h2 id="sended">Message envoyé avec succès !</h2>'); 
				}
				else if(data=="FAIL1")
				{
					$('#reponse').html('<h2 id="notsended">Merci de compléter tous les champs du formulaire</h2>');
				}
				else $('#reponse').html('<h2 id="notsended">Ce message n\'a pas pu être envoyé. Réessayez...</h2>');
			}
		});
		
		return false;
	});
	$('#reponse').ajaxStart(function() {
		$(this).html('<div id="loader">Envoi en cours ...</div>');
	});
	$('#reponse').ajaxError(function() {
		$(this).html('<h2 id="notsended">Echec de l\'envoi ! Réessayez.</h2>');
	});
	
});
