$(document).ready(function() {
	
	
	//NAVIGATION HELPER
	$("#nav li").hover(function(){
		$("ul",this).css({display:"block"});
	},function(){
		$("ul",this).css({display:"none"});
	});
	
	//ECARDS CORE FUNCTIONS
	$("#cards li").click(function(){
		$("#screeny").animate({height:"100%"},100);
		$("#cardPreview").attr("src",$("img",this).attr("src"));
		$(".formFields").show();
		$("#ecardThanks").hide();
		$("#ecardsForm").show();
	});
	$("#closeForm").click(function(){
		$("#ecardsForm").hide();
		$("#screeny").animate({height:"0px"},100);
	});
	$("#cardForm").validate({
		submitHandler:function(){
			$(".formFields").hide("fast");
			$("#ecardThanks").show("fast");
			$.get("http://www.babylosscomfort.com/grief-resources/e-cards/send.php",{ uName: $("#uName").attr("value"), uEmail:$("#uEmail").attr("value"), tEmail:$("#tEmail").attr("value"), tMessage: $("#tMessage").attr("value"), eCardType:$("#cardPreview").attr("src") },function(){
				$("#closeThanks").click(function(){
					$("#ecardsForm input,textarea").val("");
					$("#ecardsForm").hide();
					$("#screeny").hide();
				});
				$("#closeThanks").show("slow");
			});	


		}
	});
	
	
	
	//REMEMBERING BABY MEMORIAL CORE FUNCTIONS
	$("#searchMemorial").keyup(function(){
		if($(this).attr("value").length == 0){
			$(".pageNumbers").show("fast");
		}else{
			$(".pageNumbers").hide("fast");
		}
		$.get("search.php",{ searchString: $(this).attr("value") }, function(data){
		   $("#memorials").html(data);
		});
	});
	
	$("#addMemorial").click(function(){
		$("#memorials").hide("slow");
		$("#addMemorialCell").show("slow");
	});
	
	$("#cancelMemorial").click(function(){
		$("#memorials").show("slow");
		$("#addMemorialCell").hide("slow");
	});
	
	$("#memorialForm").validate({
	 submitHandler: function() {
		$("#addMemorialCell").hide("slow");	
		$("#thanks").show("slow",function(){
			setTimeout(function(){
				$.get("send.php",{ name: $("#name").attr("value"), date:$("#dateLoc").attr("value"), data:$("#data").attr("value") });				
				$("#thanks").hide("slow");
				$("#memorials").show("slow");
			},5000);
		});
	 }
	});
	$("#submitMemorial").click(function(){
		

	});	
	
	$("#dateLoc").click(function(){
		$("#datepicker").datepicker({ altField: '#dateLoc', changeYear: true});
	});	
	
	
});