$(document).ready(function()
{	

	$("a.roomimage").fancybox({
		'zoomSpeedIn':		300, 
		'zoomSpeedOut':		300, 
		'overlayShow':		true,
		'overlayOpacity':   0.7,
		'overlayColor':   '#000000'
	});
	
	

    $("div[id^=thesubmenu]").hide();
	
	if ($.cookie('activepage') != null)
	{
		var page = $.cookie('activepage');
		
		if (( page == "rooms" ) || ( page == "prices" ) || ( page == "offers" ) || ( page == "single" ) || ( page == "double" ) || ( page == "triple" ))
		{
			if (( page == "single" ) || ( page == "double" ) || ( page == "triple" ))
			{
				$("div[id^=thesubmenu3]").show();
			}
			$("div[id^=thesubmenu1]").toggle("slow");
		}
		else if (( page == "location" ) || ( page == "map" ) || ( page == "surroundings" ))
		{
			$("div[id^=thesubmenu2]").toggle();
		}
	}
	
	$(".submenu1").bind("click", function()
	{	
		$("div[id^=thesubmenu1]").toggle("slow");
		$("div[id^=thesubmenu2]").hide("slow");
		$("div[id^=thesubmenu3]").hide("slow");
    });
	
	$(".submenu3").bind("click", function()
	{	
		$("div[id^=thesubmenu3]").toggle("slow");
    });
	
	$(".submenu2").bind("click", function()
	{	
		$("div[id^=thesubmenu2]").toggle("slow");
		$("div[id^=thesubmenu1]").hide("slow");
		$("div[id^=thesubmenu3]").hide("slow");
    });
	
	$('div#themenu a').click(function() {
		var getvalue = $(this).attr('rel');
		$.cookie('activepage', getvalue);
	});
	
	// Contact form
	$("div[id^=conerror]").hide();
	$("#contact_send").click(function ()
	{
		$("div[id^=conerror]").hide();
		
		var name = $("#contact_name").val();
		var email = $("#contact_email").val();
		var comment = $("#contact_message").val();
		
		if (name == "") {  
			$("#conerror_name").show();  
			$("#contact_name").focus();  
			return false;  
		}
		
		if (email == "") {  
			$("#conerror_email").show();  
			$("#contact_email").focus();  
			return false;  
		}
		else if(!isValidEmailAddress(email))
		{
			$("#conerror_notvalid").show();  
			$("#contact_email").focus();  
			return false; 
		}
		
		if (comment == "") {  
			$("#conerror_message").show();  
			$("#contact_message").focus();  
			return false;  
		}

		var dataString = 'SendMSG=TRUE&name='+name+'&email='+email+'&comment='+comment;
		//alert(dataString); return false;
		$.ajax({
		type: "POST",
		url: "contact-send.php",
		data: dataString,
			error: function(){
				$("#conerror_script").show()
			},
			success: function() {
				$("#contact_form").hide();
				$('#contact_form').html("<br/>Your message was sent. Thank you.")
				.hide()
				.fadeIn(1500, function() {
				$('#contact_form');
				});
			}
		});
		return false;
	});
	// End contact form

});


// Email validation function
function isValidEmailAddress(emailAddress) 
{
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
}
//End Email validation function