$(function() { 
//=========================================================
//												MAP OVERLAY
//---------------------------------------------------------	
//        $("a#close_map[rel]").overlay({
//        	expose: { 
//        	        color: '#333', 
//        	        loadSpeed: 150, 
//        	        opacity: 0.5 
//       	    }, 
//        	color: 	'#999', 
//        	effect: 'apple'
//        }); 
        
//=========================================================
//											   SLIDING TEXT
//---------------------------------------------------------	
	var $paneTarget = $("body");
	
	var $concept_status = false;
	var $concept_en_status = false;
	var $map_status = false;
	
	
	$('a#close_concept_txt').click(function(){
		if ($concept_status) {
			$('#concept_txt').slideUp("slow");
			$('a#close_concept_txt').html("En savoir plus");
			$concept_status = false;
		} else {
			$('#concept_txt').slideDown("slow");
			$('a#close_concept_txt').html("Replier le texte");
			$concept_status = true;
		}
		return false;
	});
	
	$('a#close_concept_en_txt').click(function(){
		if ($concept_en_status) {
			$('#concept_en_txt').slideUp("slow");
			$('a#close_concept_en_txt').html("Show more");
			$concept_en_status = false;
		} else {
			$('#concept_en_txt').slideDown("slow");
			$('a#close_concept_en_txt').html("Fold the text");
			$concept_en_status = true;
		}
		return false;
	});
	
	$('a#close_map').click(function(){
		if ($map_status) {
			$('#googleMap').stop().slideUp("slow", function(){
				$('.adresse').stop().slideDown("slow");
				$('a#close_map').html("VOIR LA CARTE");
				$map_status = false;
			});
		} else {
			$('.adresse').stop().slideUp("slow", function(){
				$('#googleMap').stop().slideDown("slow");
				$('a#close_map').html("Replier la carte");
				$map_status = true;
			});
		}
		return false;
	});   
		   
//=========================================================
//												NAVIGATION
//---------------------------------------------------------	

	$('.vlog_btn').click(function(){

		$paneTarget.stop().scrollTo(0, 800);

		return false;

	});

	

	$('.concept_btn').click(function(){

		$paneTarget.stop().scrollTo('#concept', 800);

		return false;

	});
	
	$('.menu_btn').click(function(){
		$paneTarget.stop().scrollTo('#menu', 800);
		return false;
	});
	
	$('.groupes_btn').click(function(){
		$paneTarget.stop().scrollTo('#groupes', 800);
		return false;
	});

	

	$('.rsvp_btn').click(function(){

		$paneTarget.stop().scrollTo('#rsvp', 800);

		return false;

	});	
//---------------- //navigation
//=========================================================
//											   FORMULAIRES
//---------------------------------------------------------
	var nom = 		'NOM / LAST NAME';	var fullnom = 'NOM / NAME';
	var prenom = 	'PRÉNOM / NAME';
	var telephone =	'TELEPHONE';
	var courriel = 	'EMAIL';
	var invites = 	'NOMBRE D\'INVITÉS / NUMBER OF GUESTS';
	var date = 		'DATE ET HEURE / DATE AND TIME';
	var note = 		'NOTE';
	

	$('input#nom').each(function () {

		if ($(this).val() == '') {

			$(this).val(nom);

		}

	}).focus(function () {

		if ($(this).val() == nom) {

			$(this).val('');

		}

	}).blur(function () {

		if ($(this).val() == '') {

			$(this).val(nom);

		}

	});
		$('input#wp-email-capture-name').each(function () {		if ($(this).val() == '') {			$(this).val(fullnom);		}	}).focus(function () {		if ($(this).val() == fullnom) {			$(this).val('');		}	}).blur(function () {		if ($(this).val() == '') {			$(this).val(fullnom);		}	});					$('input#wp-email-capture-email').each(function () {		if ($(this).val() == '') {			$(this).val(courriel);		}	}).focus(function () {		if ($(this).val() == courriel) {			$(this).val('');		}	}).blur(function () {		if ($(this).val() == '') {			$(this).val(courriel);		}	});
	$('input#prenom').each(function () {
		if ($(this).val() == '') {
			$(this).val(prenom);
		}
	}).focus(function () {
		if ($(this).val() == prenom) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val(prenom);
		}
	});
	
	$('input#telephone').each(function () {
		if ($(this).val() == '') {
			$(this).val(telephone);
		}
	}).focus(function () {
		if ($(this).val() == telephone) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val(telephone);
		}
	});
	
	$('input#courriel').each(function () {
		if ($(this).val() == '') {
			$(this).val(courriel);
		}
	}).focus(function () {
		if ($(this).val() == courriel) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val(courriel);
		}
	});
	
	$('input#invites').each(function () {
		if ($(this).val() == '') {
			$(this).val(invites);
		}
	}).focus(function () {
		if ($(this).val() == invites) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val(invites);
		}
	});
	
	$('input#date').each(function () {
		if ($(this).val() == '') {
			$(this).val(date);
		}
	}).focus(function () {
		if ($(this).val() == date) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val(date);
		}
	});
	
	$('input#note').each(function () {
		if ($(this).val() == '') {
			$(this).val(note);
		}
	}).focus(function () {
		if ($(this).val() == note) {
			$(this).val('');
		}
	}).blur(function () {
		if ($(this).val() == '') {
			$(this).val(note);
		}
	});		

//---------------- //formulaires
//=========================================================
//											    ENVOI MAIL
//---------------------------------------------------------
//	$("#emailusbtn").click(function(){
//		$("#form_status").hide("fast");
//		$(".error").removeClass("error");
//		$("#form_status").html('');
//		$("#javacheck").val(Math.random());
//		var javacheckVal = $("#javacheck").val();
//		
//		var hasError = false;
//		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
//		
//		var courrielToVal = $("#courriel").val();
//		if (courrielToVal == '' || courrielToVal == 'Votre courriel') {
//			$("#courriel").addClass("error");
//			hasError = true;
//		} else if (!emailReg.test(courrielToVal)) {	
//			$("#courriel").addClass("error");
//			hasError = true;
//		}
//		
//		var nomVal = $("#nom").val();
//		if (nomVal == '' || nomVal == 'Votre nom' ) {
//			$("#nom").addClass("error");
//			hasError = true;
//		}
//		
//		var prenomVal = $("#prenom").val();
//		if (prenomVal == '' || prenomVal == 'Votre prénom' ) {
//			$("#prenom").addClass("error");
//			hasError = true;
//		}
//		
//		var telephoneVal = $("#telephone").val();
//		if (telephoneVal == '' || telephoneVal == 'Votre téléphone' ) {
//			$("#telephone").addClass("error");
//			hasError = true;
//		}
//		
//		var invitesVal = $("#invites").val();
//		if (invitesVal == '' || invitesVal == "Nombre d'invités" ) {
//			$("#invites").addClass("error");
//			hasError = true;
//		}
//		
//		var dateVal = $("#date").val();
//		if (dateVal == '' || dateVal == "Date et heure" ) {
//			$("#date").addClass("error");
//			hasError = true;
//		}
//		
//		var noteVal = $("#note").val();
//		if (noteVal == "Note" ) {
//			noteVal = '';
//		}
//		
//		if (hasError == false) {
//			$.post(mailpath,
//   				{ nom: nomVal, prenom: prenomVal, courriel: courrielToVal, telephone: telephoneVal, invites: invitesVal, date: dateVal, note: noteVal, 
//   					javacheck: javacheckVal,
//   					success: function(){
//						$("#emailus").slideUp("normal", function() {				   
//							$("#form_status").html('<strong>Success!</strong> Your email has been sent.').show("slow");
//							window.setTimeout(function() {
//								$("#form_status").hide("slow");
//								$("#emailus").slideDown("normal");
//							}, 5000);
//						});
//   					}
//   					}
//				 );
//		} else {
//			$("#form_status").html('Veuillez remplir les champs requis / Please fill in all required fields').show("slow");
//			return false;
//		}
//		
//		
//	});


var ajax_submit_options = {
		url: mailpath,
		success: showResponse,
		dataType: 'json',
		resetForm: true // reset the form after successful submit
};

	// validate form when it is submitted
	$("#emailus").validate({
		rules: {
			prenom: "required",
			nom: "required",
			telephone: {
				required: true,
				minlength: 7
			},
			courriel: {
				required: true,
				email: true
			},
			invites: {
				required: true,
				number: true,
				min: 1
			},
			dateISO: {
				required: true,
				date: true
			}
		}, 	messages: {
			prenom: "Please enter your firstname",
			nom: "Please enter your lastname",
			telephone: {
				required: "Please enter your telephone number",
				minlength: "Your telephone number must consist of at least 7 characters"
			},
			courriel: "Please enter a valid email address",
			invites: {
				required: "Please provide the number of guests",
				number: "Number of guests must be positive",
				min: "Number of guests must be positive"
			},
			date: "Please enter a date in format 'YYYY-MM-DD hh:mm'"
		},
		submitHandler: function (form){
			$(form).ajaxSubmit(ajax_submit_options);
		}
	});
	
	$('#sendmail_messages_holder_close').click(function(){
		$('#sendmail_messages_holder').fadeOut(1000);
	});
});


// post-submit callback 
function showResponse(responseObj)  { 
	if ('OK' == responseObj.status){
		$('#sendmail_messages').html('<p class="success">Réservation envoyée - Reservation submitted</p>');
		setTimeout(
			function(){
				$('#sendmail_messages_holder').fadeOut(1000);
			}, 7000);
	}else{
		$('#sendmail_messages').empty();
		$('#sendmail_messages').append('<p class="header">Message :</p>');
		$.each(responseObj.errors, function(index, value){
			$('#sendmail_messages').append('<p>'+value+'</p>');
		});
	}
				window.alert( 'Réservation envoyée - Reservation submitted' );

	$('#sendmail_messages_holder').show();
	
}

