

	
		var button;
		var userInfo;
		
		window.fbAsyncInit = function() {
		
		
			FB.init({
				appId: '118989061536194',
				status: true,
				cookie: true,
				xfbml: true,
				oauth: true
			});


		function go(response) {
		
			button = document.getElementById('fbLogin');
			
			if (response.authResponse) 
			{ 
				//user is already logged in and connected
				FB.api('/me', function(info) {
					login(response, info);
					jQuery('#fbLogin').hide();
				});
				
				button.onclick = function() {
					FB.logout(function(response) {
						logout(response);
					});
				};
				
				//alert("connected!");
				
			} else { 
				
				//alert("not connected!");
				
				//user is not connected to your app or logged out
				button.onclick = function() {
					FB.login(function(response) {
						if (response.authResponse) {
							FB.api('/me', function(info) {
								login(response, info);
							});
						} else { //user cancelled login or did not grant authorization
							//showLoader(false);
						}
					}, {
						scope: 'email,publish_stream'
					});
				}
			}

		} // run once with current status and whenever the status changes
		
		FB.getLoginStatus(go);
		FB.Event.subscribe('auth.statusChange', go);

	};

	
	(function() {
		var e = document.createElement('script');
		e.async = true;
		e.src = document.location.protocol + '//connect.facebook.net/fr_FR/all.js';
		document.getElementById('fb-root').appendChild(e);
	}());

	function login(response, info) {
		if (response.authResponse) {
			$(function() {
				$('#lastname').val(info.last_name);
				$('#firstname').val(info.first_name);
				if (info.email != "") {	$('#email').val(info.email); }
			});
		}
	}
	


		$(document).ready(function(){
		
  
			$("#logo").delay(2000).animate({ 'margin-left': '10px' }, 1000, function() { 	});
			$("#titre").delay(2500).animate({ 'margin-left': '10px' }, 1000, function() { 	});
			$(".bout").delay(2500).animate({ 'margin-left': '15px' }, 1000, function() { 	});
			$("#video").delay(3000).animate({ 'margin-left': '5px' }, 1000, function() { 	});
	
			$('.bout').live('click', function(e) {
					e.preventDefault();
					$('#video').animate({ 'margin-left': '-500px' }, 700, function() { 	}); //.fadeOut();
					$('#formulaire').delay(1000).fadeIn().animate({ 'margin-left': '17px' }, 700, function() { 	});
				});
	
			$('#close').live('click', function(e) {
					e.preventDefault();
					$('#video').delay(1000).animate({ 'margin-left': '5px' }, 700, function() { 	}); //.fadeOut();
					$('#formulaire').animate({ 'margin-left': '-250px' }, 700, function() { 	});
			});
	
	
	
			// CENTRER VERTICALEMENT LE DIV GLOBAL
			$(window).resize(function() {
				var container = $('#global');
				var windowHeight = $(window).get(0).innerHeight;
				var containerHeight = container.height();
				var yPos = (windowHeight-containerHeight)/2;
				if (containerHeight > windowHeight) 
				{
					container.css('margin-top', "0px");
				} else 
				{
					container.css('margin-top', yPos+"px");
				}
			});		
			
			$(window).trigger('resize');
			
			// GESTION DES CHAMPS
			$('#myForm input').focus(function() {
					if ($(this).val() === $(this).attr('start_value') ) {
						$(this).val("");
					}
				}).blur(function() {
					if ($(this).val() === "") {
						$(this).val($(this).attr('start_value'));
					}
				});

			// VALIDATION FORMULAIRE
			$("#myForm").submit(function() {
				if (validateString($("#lastname")) & validateEmail($("#email")) & validateString($("#firstname")) ) {
					//alert("Vous allez recevoir dans quelques intants un lien sur votre Email !");
					jQuery('#form_container').hide();
					jQuery('#response').delay(300).fadeIn();
					return true
				} else {
					return false;
				}
			}); 

			
			function validateEmail(email) {		
				var filter = /^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
				if (filter.test(email.val())) {
					email.removeClass("error");
					return true;
				} else {
					email.addClass("error");
					return false;
				}
			}		
			
			function validateString(string) { 				
				if (string.val().length < 3 || string.val() === string.attr('start_value') ) {
					string.addClass("error");
					return false;
				} else {
					string.removeClass("error");
					return true;
				}
			}
			
		
		});



		
