$(document).ready(function() {

	$('#newsletter-courriel').focus(function() {
		$('#newsletter-courriel').val("");
	});

	$('#newsletter-bouton').click(function() {
		if ($('#newsletter-courriel').val().length > 2) {
			$.ajax({
				type: "POST",
				url: "../modules/site/ajax/envoi_newsletter.php",
				data: ({'courriel' : $('#newsletter-courriel').val()}),
				success: function(data) {
					$('#newsletter-message').html(data);
					$('#newsletter-courriel').val("");
					$('#newsletter-message').slideDown();
				}
			});
		} else {
			alert('Vous devez remplir tout les champs');
		}
	});

	$('#question-bouton').click(function() {
		if ($('#questions-nom').val().length > 2
		&& $('#questions-courriel').val().length > 2
		&& $('#questions-question').val().length > 2) {
			$.ajax({
				type: "POST",
				url: "../modules/site/ajax/envoi_question.php",
				data: ({'nom' : $('#questions-nom').val(),
					'courriel' : $('#questions-courriel').val(),
					'question' : $('#questions-question').val()}),
				success: function(data) {
					//$('#questions-form').html(data);
					$('#questions-message').html(data);
					$('#questions-nom').val("");
					$('#questions-courriel').val("");
					$('#questions-question').val("");
					$('#questions-message').slideDown();
				}
			});
		} else {
			alert('Vous devez remplir tout les champs');
		}
	});
	
	$('#bulles-lrg').fadeIn(500).delay(800).fadeOut(500);
	$('#bulles-med').delay(900).fadeIn(500).delay(800).fadeOut(500);
	$('#bulles-sml').delay(1800).fadeIn(500).delay(800).fadeOut(500);
	
	setInterval(function() {
		$('#bulles-lrg').fadeIn(500).delay(800).fadeOut(500);
		$('#bulles-med').delay(900).fadeIn(500).delay(800).fadeOut(500);
		$('#bulles-sml').delay(1800).fadeIn(500).delay(800).fadeOut(500);
		
		
		var rand = Math.floor((Math.random() * 1000) % 2);
		if (rand == 0) {
			$('#wouaf').css('top', '35px');
			$('#wouaf').css('right', '200px');
			$('#wouaf').html("miaw!");
		} else {
			$('#wouaf').css('top', '60px');
			$('#wouaf').css('right', '220px');
			$('#wouaf').html("woaf!");
		}
		
	}, 1 * 6000);
});
