$(function() {
	$(".meetingTab:first").show();
	$("#lowerSection").css("width", "0").css("height", "17px");
	
	var contentRight = null;
	
	function showTab(whatTab) {
		var source = $(whatTab).attr("href");
		var target = "#" + source;
		$(target).fadeIn("slow"/*, downlow*/);
	}
	
	$("ul#meetingTabLinks li a").click(
		function() {
			if($(this).attr("id") != "roomplannerlink") {
			if($(this).attr("href") == "conventions") {
				contentRight = "480";
			}
			if($(this).attr("href") == "meetings") {
				contentRight = "380";
			}
			if($(this).attr("href") == "floorPlans") {
				contentRight = "456";
			}
			if($(this).attr("href") == "meetingOffers") {
				contentRight = "621";
			}
			if($(this).attr("href") == "requestProposal") {
				
				contentRight = "1506";
			} 
			$("ul#meetingTabLinks li a").removeClass("active");
			$(this).addClass("active");
			$(".meetingTab").hide();
			$("#thePlans").hide();
			$("#theForm").hide();
			$("#content").animate(
				{height: (contentRight + "px")}, 1000, showForm);
			showTab(this);
			if($(this).attr("href") == "floorPlans") {
				$("#thePlans").fadeIn("slow");
			}
			/*if($(this).attr("href") == "requestProposal") {
				$("#theForm").fadeIn("slow");
			}*/
			return false;
		}
		}
	);
	
	function showForm() {
		if($("ul#meetingTabLinks li a#reqPos").hasClass("active")) {
		$("#theForm").fadeIn("slow");
		}
	}
	
	function showPlan(whatPlan) {
		var source = $(whatPlan).attr("class");
		var target = "#" + source;
		$(target).fadeIn("slow");
	}
	
	$("#floorPlans ul li").click(
		function() {
			$("#thePlans img").hide();
			showPlan(this);
			return false;
		}
	);
	
	$("p#sendBtn input").click(
		function() {
			var emailPattern =/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
			var email = $("input#e-mail").attr("value");
			var eTest = emailPattern.test(email);
			if($("input#name").attr("value") == "") {
				alert("Inserisca il nome");
				return false;
			} else if(eTest == false) {
			alert("l'indirizzo di posta elettronica inserito non risulta valido");
			return false;
			} else {	
				$("#theForm").fadeOut("slow");
				$("#content").animate({height: "187px"}, 1000);
				$("#formLoading").fadeIn("slow");
				$('#molinoForm').ajaxForm(function() {   
				$("#formLoading").hide();			 
				$("#formSuccess").fadeIn("slow");
				}); 
				/*$.post("contact/sendmail.php",
					function(data){
					$("#theForm").fadeOut("slow");
					$("#content").animate({height: "400px"}, 1000);
					$("#formSuccess").fadeIn("slow", 
						function() {
							alert("success");
						});
					}
				);	*/
			}
		}
	);
	
	$("p#clearBtn").click(
		function() {
			$("input").attr("value", "");
			$("input#send").attr("value", "INVIO");
			$("textarea").attr("value", "");
			$("select").attr("value", "Prego selezionare...");
		}
	);
	
	$("p#printForm").click(
		function() {
			print();
		}
	);
});
