// Méthode validator
$.validator.addMethod("dateFR", function(value, element) {
	var validDate = /^([0-9]{2})-([0-9]{2})-(20[0-9]{2})$/;
	return validDate.test(value);
}, 'Date non valide !');

// Fonctions Google maps
	function initialize(gmlat, gmlong) {
		var local1 = new google.maps.LatLng(gmlat,gmlong);
		var centerPoint = new google.maps.LatLng((parseFloat(gmlat) + 0.001212),gmlong);
		var optionsCarte1 = {
			zoom: 15,
			center: centerPoint,
			//mapTypeControl: false,
			mapTypeId: google.maps.MapTypeId.HYBRID
		}
		var maCarte = new google.maps.Map(document.getElementById("google_maps"), optionsCarte1);
		
		var contenuinfoBulle1 = '<img src="guesthouse/logo.png" alt="Esprit libre" />';
		var infoBulle1 = new google.maps.InfoWindow({
			 content: contenuinfoBulle1
		})
		var optionsMarqueur1 = {
			  position: local1,
			  map: maCarte,
			  title: "Esprit Libre"
		}
		var marqueur1 = new google.maps.Marker(optionsMarqueur1);
		google.maps.event.addListener(marqueur1, 'click', function() {
				maCarte.panTo(local1);
				maCarte.setZoom(18);
				infoBulle1.open(maCarte, marqueur1);
		});
		infoBulle1.open(maCarte, marqueur1);
	}


// Actions après chargement de la page ////////////////////////////////////////////////////////////////////////////////////////////
	$(document).ready(function() {
		
		//fancybox
		$("#mainContent div.article > a").fancybox();
		$("a#link_map").fancybox({
			onComplete : function() { initialize( $("a#link_map").attr("gmlat"), $("a#link_map").attr("gmlong") ); }
		});
		
		// Smooth scrolling
		function filterPath(string) {
		  return string
			.replace(/^\//,'')
			.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
			.replace(/\/$/,'');
		  }
		  var locationPath = filterPath(location.pathname);
		  var scrollElem = scrollableElement('html', 'body');
		 
		  $('a[href*=#].smooth').each(function() {
			var thisPath = filterPath(this.pathname) || locationPath;
			if (  locationPath == thisPath
			&& (location.hostname == this.hostname || !this.hostname)
			&& this.hash.replace(/#/,'') ) {
			  var $target = $(this.hash), target = this.hash;
			  if (target) {
				var targetOffset = $target.offset().top;
				$(this).click(function(event) {
				  event.preventDefault();
				  $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
					location.hash = target;
				  });
				});
			  }
			}
		  });
		 
		  // use the first element that is "scrollable"
		  function scrollableElement(els) {
			for (var i = 0, argLength = arguments.length; i <argLength; i++) {
			  var el = arguments[i],
				  $scrollElement = $(el);
			  if ($scrollElement.scrollTop()> 0) {
				return el;
			  } else {
				$scrollElement.scrollTop(1);
				var isScrollable = $scrollElement.scrollTop()> 0;
				$scrollElement.scrollTop(0);
				if (isScrollable) {
				  return el;
				}
			  }
			}
			return [];
		  }
		
		// $ feature list
		$.featureList(
			$("#icos ul li"),
			$("#ads li"), {
				start_item	:	0
			}
		);
		
		// $.validator
		$("#contact").validate({
			submitHandler:function(form) {
				SubmittingForm();
			},
			rules: {
				nom: "required",
				email: {
					required: true,
					email: true
				},
				message: "required"
			},
			messages: {
				nom: "Champs obligatoire !",
				email: "Email non-valide !",
				message: "Champs obligatoire !"
			}
		});
		$("#booking").validate({
			submitHandler:function(form) {
				SubmittingForm();
			},
			rules: {
				name: "required",
				email: {
					required: true,
					email: true
				},
				dateArrivee: {
					required: true,
					dateFR: true
				},
				dateDepart: {
					required: true,
					dateFR: true
				}
			},
			messages: {
				name: "Champs obligatoire !",
				email: "Email non-valide !",
				dateArrivee: "Date non-valide !",
				dateDepart: "Date non-valide !"
			}
		});
		
		// Datepicker		
		$.datepicker.regional['fr'] = {clearText: 'Effacer', clearStatus: '',
		closeText: 'Fermer', closeStatus: 'Fermer sans modifier',
		prevText: '<Préc', prevStatus: 'Voir le mois précédent',
		nextText: 'Suiv>', nextStatus: 'Voir le mois suivant',
		currentText: 'Courant', currentStatus: 'Voir le mois courant',
		monthNames: ['Janvier','Février','Mars','Avril','Mai','Juin',
		'Juillet','Août','Septembre','Octobre','Novembre','Décembre'],
		monthNamesShort: ['Jan','Fév','Mar','Avr','Mai','Jun',
		'Jul','Aoû','Sep','Oct','Nov','Déc'],
		monthStatus: 'Voir un autre mois', yearStatus: 'Voir un autre année',
		weekHeader: 'Sm', weekStatus: '',
		dayNames: ['Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi'],
		dayNamesShort: ['Dim','Lun','Mar','Mer','Jeu','Ven','Sam'],
		dayNamesMin: ['Di','Lu','Ma','Me','Je','Ve','Sa'],
		dayStatus: 'Utiliser DD comme premier jour de la semaine', dateStatus: 'Choisir le DD, MM d',
		dateFormat: 'dd/mm/yy', firstDay: 0, 
		initStatus: 'Choisir la date', isRTL: false};
		$.datepicker.setDefaults($.datepicker.regional['fr']);
		
		$("#bk_arrival, #bk_departure").datepicker({ dateFormat: 'dd-mm-yy', firstDay:1 });
		
		
});
	
