$(document).ready(function(){ 

	$('#1.saying').fadeIn(1000); 
	sayings(1,$('.saying').size());

	
	$('#mailinglist_form').submit(function() {
		mailing_list_submit();
		return false;
	});

	$('#text_content #mid div:first').fadeIn(10); 
	var current_content = 'thereunion';
	$('#menubar ul li').click(function(){
		var new_content = (this).id;
		if (current_content != new_content) {
			$('#text_content #mid #content_'+current_content).fadeOut(500,function() {
				$('#text_content #mid #content_'+new_content).fadeIn(500);
			});
			current_content = new_content;
		}
	});

	$("#contact_link").click( function() {
		var topPosition = Math.round($(window).height()/2)-200;
		var leftPosition = Math.round($(window).width()/2)-250;
		$('#contact').animate(
			{ left: (leftPosition),top: (topPosition) }, 
			{ duration: 1000, easing: 'easeInOutCirc' }
		);	
	});
	$("#hide_contact_link").click( function() {
		$('#contact').animate(
			{ left: (-600),top: (-600) }, 
			{ duration: 1000, easing: 'easeInOutCirc' }
		);	
	});


	$("#contact_form input").focus(function(){
		var a = '';
		$(this).val(a);
    });
	$("#contact_form textarea").focus(function(){
		var a = '';
		$(this).val(a);
    });
	$("#contact_form #submit_button").click(function() {
		var email = $('input[id=email_address]');
		if (email.val().length == 0 || email.val() == 'your email address') {
			alert('Please enter your email address.');
	        return false;
		}
		var subject = $('input[id=subject]');
		if (subject.val().length == 0 || subject.val() == 'subject') {
			alert('Please enter a subject for your email.');
	        return false;
		}
		var data = $("#contact_form").serialize();
		$.ajax({
			type: "POST",
			url: '/functions/contact_send.php',
	        dataType: "text",
	        data: data,
			error: function(){ alert('Sorry, an error occurred.  Please try again.'); },
			success: function(a) {
				$('#contact_form').html(a);
			}
		});
		return false;
    });

	function sayings(start,end) {
		$('#'+(start-1)).fadeOut(1000); 
		$('#'+start).fadeIn(1000); 
		if (start++ > end) { start = 1;}
		setTimeout(function(){sayings(start,end);}, 6000); 
	}


	
	function mailing_list_submit() {
		var email_address = $('input[id=email_address]');
		if (email_address.val().length == 0) {
			alert('You must enter your email address.');
	        return false;
		}

		var data = $("#mailinglist_form").serialize();
		$.ajax({
			type: "GET",
			url: '/functions/mailing_list_submit.php?email_address='+email_address.val(),
			error: function(){ alert('Sorry, an error occurred.  Please try again.'); },
			success: function(a) {
				if (a.match('Error')) {
					$('#email_response').html(a);
				} else {
					$('#mailinglist_form').html(a);
				}
			}
		});
	    return false;
	}




});

