// JavaScript Document

// General

function validateEmail(email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   if(reg.test(email) == false) {
      return false;
   } else {
			return true;
	 }
}

// Gallery

$(function(){
	var dir = '/images/gallery/';	
	$('.swapImage').click(function(){
		var src = $(this).attr('title');
		var content = '<img src="'+dir+src+'" alt="" />';
		$('#mainimage').fadeOut('fast', function(){
				$('#mainimage').html(content).fadeIn('slow');														 
		});
	});
});



// Bookings 

$(function(){
	$('#submitForm').click(function(){
		if($('#name').val() == ''){
			$('#error').html('Please ensure that you compelte all fields marked with an asterisk').fadeIn();
			$('#name').focus();
		}else if($('#email').val() == ''){
			$('#error').html('Please ensure that you compelte all fields marked with an asterisk').fadeIn();
			$('#email').focus();
		}else{
			if(validateEmail($('#email').val())){
				$('#bookingForm').submit();
			} else {
				$('#error').html('Your email address is not valid').fadeIn();
				$('#email').val('');
				$('#email').focus();
			}
		}
	});
});


$(function(){
	$('#getDirections').click(function(){
		map.clearOverlays(); 
		var fromAddress = $('#fromAddress').val();
		var toAddress = "52.929149, 1.225001";
		setDirections(fromAddress, toAddress, 'en_uk');
		$('#map_directions').fadeIn();
	});
});
