$(document).ready(function() {
	/*
	$('#indexLink').hover(
			function() {$('#logoLight').fadeIn(200)},
			function() {$('#logoLight').fadeOut(200)}
	);
	*/
	$('#gallery a').each(function(index) {
		$(this).delay(index * 150).fadeIn(1500);
	});

	/*
	$('#gallery img').each(function(index) {
		$(this).mouseenter(function() {
			$(this).animate({borderWidth: 3}, 100, null);
		});
		$(this).mouseleave(function() {
			$(this).animate({borderWidth: 0}, 100, null);
		});
	});
	 */

	//using drop effect for showing menu images (or slide or blind)
	/*
	$('.menu a').each(function(index) {
		$(this).hover(
				function(){$('#' + this.id + ' img').fadeIn(500);},
				function(){$('#' + this.id + ' img').fadeOut(500);});
	});
	 */

	$('.menu a').each(function(index) {
		$(this).hover(
				function(){$('#' + this.id + 'Preview').fadeIn(400);},
				function(){$('#' + this.id + 'Preview').fadeOut(400);});
	});

	/*
	$('.menu a').each(function(index) {
		$(this).hover(
				function(){
					$('#' + this.id + 'Preview').fadeIn(500);
					$('#' + this.id).animate({
						fontSize: "12pt"
					}, 100);
				},
				function(){
					$('#' + this.id + 'Preview').fadeOut(500);
					$('#' + this.id).animate({
						fontSize: "10pt"
					}, 100);
				});
	});
	 */

	//$("#tabs").tabs();

	//using fade in/out to show/hide activites
	$('#activites-menu a').each(function(index) {
		$(this).click(function(event){
			var selectedLinkId = this.id;
			$('#activites-' + this.id).fadeIn(1000);

			$('.activites-content-element').each(function(index) {
				if (this.id != ('activites-' + selectedLinkId)) {
					$(this).fadeOut(1000);
				}
			});
		});
	});

	$('#activites-menu a').each(function(index) {
		$(this).hover(
				function(){$('#' + this.id + '-label').fadeTo(400, 0.80);},
				function(){$('#' + this.id + '-label').fadeTo(400, 0);});
	});

	//Google maps api
	if (document.getElementById("map_canvas") != null && document.getElementById("map_canvas") != 'undefined') {
		var myLatlng = new google.maps.LatLng(46.619467, 7.163644);
		//var myLatlng = new google.maps.LatLng(-34.397, 150.644);
		var myOptions = {
				zoom: 8,
				center: myLatlng,
				mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		var map = new google.maps.Map(document.getElementById("map_canvas"),
				myOptions);

		//var image = './images/iconEtoile.png';

		var marker = new google.maps.Marker({
			position: myLatlng,
			map: map,
			/*icon: image,*/
			title:"Hotel de l'Etoile"
		});

		// To add the marker to the map, call setMap();
		//marker.setMap(map);  
	}

	//fade in on page refresh
	$("#content").fadeIn(1000);

	//initialize slideSwitch for restaurant and chambres sections
	slideSwitch('content-restaurant-left-img');
	slideSwitch('content-restaurant-bottom-img');
	slideSwitch('content-chambres-left-img');
	slideSwitch('content-chambres-bottom-img');
});


//enable lightBox gallery
$(function() {
	$('#gallery a').lightBox();
});

function contactValidate() {
	var fieldMessage = $(":hidden#invalidField").val();
	var mailMessage = $(":hidden#invalidMail").val();
	
	var failed = false;
	$(":text").each(function() {
		if ($(this).val() == "") {
			failed = true;
		}
	});

	if ($("textarea#message").val() == "") {
		failed = true;
	}

	if (failed) {
		alert(fieldMessage);
	}
	
	var email = $(":text#email").val();
	if (!failed && !validateEmail(email)) {
		alert(mailMessage);
		failed = true;
	}
	return !failed;
}

function validateEmail(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	//var reg 	= /^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,3}$/
		if (reg.exec(email) == null)
		{
			return false;
		}
		else
		{
			return true;
		}	
}

//interval function to change image in restaurant and chambres section
function slideSwitch(divId) {
	if (index == 2) {
		index = 0;
	} else {
		index++;
	}

	var imgs = $('#' + divId + ' img');
	$('#' + divId + ' img').each(function(i) {
		if (i == index) {
			$(this).fadeIn(2000);
		} else {
			$(this).fadeOut(2000);
		}
	});
}

//select a picture for restaurant/chambres section between 0 and 2
var index = Math.floor(Math.random()*3+1) - 1;


function delayedSlideSwitch() {
	setInterval("slideSwitch('content-restaurant-bottom-img')", 6000);
	setInterval("slideSwitch('content-chambres-bottom-img')", 6000);
}

$(function() {
	setInterval("slideSwitch('content-restaurant-left-img')", 6000);
	setInterval("slideSwitch('content-chambres-left-img')", 6000);
	setTimeout("delayedSlideSwitch()", 3000);
});


