$(function() {
	$('#start_date, #end_date').datepicker();
	
	$('ul#tab').click(function() {
		$('#dropdown_container').animate({
			'top': 0	
		});
		
		$('p#close_button').fadeIn('slow');
	});
	
	$('p#close_button').click(function() {
		$('#dropdown_container').animate({
			'top': '-265px'	
		});
		
		$('p#close_button').fadeOut('fast');
	});
	
	$('#volunteer_form').submit(function() {
		var error = 0;

		if ($('#full_name').val() == '') {
			error = 1;
		}
		
		if ($('#email').val() == '') {
			error = 1;
		}

		if (error === 1) {
			alert('Oops! Please fill out the highlighted fields and try again...');
		} else {
			var post_vars = $(this).serialize();
			post_vars += '&action=volunteer_add'

			$.ajax({
			   	type: "POST",
			   	url: 'http://173.203.102.128/habitat_wordpress/wp-admin/admin-ajax.php',
			   	data: post_vars,
			   	success: function(data) {
				
					$('#full_name').val('');
					$('#email').val('');
					$('#hours').val('');
					$('#start_date').val('');
					$('#end_date').val('');
					
			     	alert('Thanks! Your information has been sent.');
			   	}
			});
		}
		
		return false;
	});
	
	// hero
	$('#hero_photos img').hide();
	$('#hero_photos img:eq(0)').show();
	
	$.each($('#hero_photos img'), function() {
		$('<a class="hero_link" href="#"></a>').appendTo('#hero_links');
	});
	
	$('.hero_link').click(function() {
		var index = $(this).index();
		
		$('#hero_photos img:visible').fadeOut(function() {
			$('#hero_photos img:eq('+index+')').fadeIn();
		});
		
		return false;
	});
	
});
