// wait until the DOM is ready
$(document).ready(function() {
	// 'show more' copy on the homepage
		// hide the extra text
		$("#indexMore").css("display","none");
		// sho the 'read more' copy
		$("#readMoreIndex").css("display","block");
		
		// show the rest of the copy on click (toggle)
		$("#readMoreIndex").click(function() {
			$("#indexMore").slideToggle("slow");
			$("#readMoreIndex").css("display","none");
			return false;
		});
		
	// blog search show / hide default value
		$('input#s').focus(function () {
			if ($(this).val() == "search") { $(this).val(""); }
		});
			
		$('input#s').blur(function () {
			if ($(this).val() == "") { $(this).val("search"); }
		});
		
	// mailing list form Ajax
		// setup mailing form click
		function wireUp() {
			$("#mailingForm").submit(function() {
				submitAjaxForm("#mailingForm", "../include/mailingListForm.php", "#mailingFormContainer");
				return false;					  
			})
			$("#propForm").submit(function() {
				submitAjaxForm("#propForm", "../include/propForm.php", "#propFormContainer");
				return false;				  
			})	
		}
		
		// form submitted, lets Ajax!
		function submitAjaxForm(formId, formUrl, containerToUpdate){
			$("#ajaxMailingLoader").css({'display' : 'inline'}); // show the ajax loader icon
			var inputs = $(formId).serialize(); // grab all the form inputs
			
			jQuery.ajax({
				type: "POST",
				data: inputs, 
				url: formUrl,
				error: function(html) { 
					// load response to form 
					//alert(html);
				},
				success: function(html) { 
					// load response to form 
					$(containerToUpdate).html(html);
					wireUp();
				}
			})
		}
		
		wireUp();

}); 