$(window).load(function() {
	$('#slider').nivoSlider({
	effect: 'fade',
	animSpeed: 550,
	pauseTime: 5500,
	controlNav: false,
	keyboardNav: false
	});
});

$(document).ready( function(){
	
	$("<span class='h1'>" + $("#copy h1:first").text() + "&nbsp;</span>").prependTo( $("#copy p:first") );
	$("#copy h1:first").remove();
	
	$(".pod h2").prepend("&middot; ").append(" &middot;");
	
	$("#hp_contact").live("submit", function(){

		var p = $(this).find(".formcontents");
		var valt = $(this).find(".textarea:last").val();
		var valn = $(this).find(".input:first").val();
		if ( valt == "" || valt == "Message" || valn == "" || valn == "Your Name" ) {
			alert('Your information was not submitted. You must provide your name and a message.');
			return false;
		}
		
		p.hide('slide', {direction: 'left'}, 400 );
		
		var serdata = $(this).serialize();
		$.post( "/submit.php", serdata, function(data) {
			_gaq.push(['_trackPageview', '/submit-homepage-form/' ]);
			if ( data == "[OK]" ) {
				p.html('<p class="note">Thanks! We have received your information and will be in touch soon.</p>');
				$('<p class="action"><a href="/contact/">Contact Us &gt;</a></p>').insertBefore(".submit");
				$(".submit").remove();
			} else {
				p.prepend('<p class="note err">There was a problem. Please try again.</p>');
			}
			p.show('slide', {direction: 'right'}, 700 );
		});
		
		return false;
	});
	
	$(".pod").each( function(){
		var href = $(this).find(".action").children("a").attr("href");
		$(this).attr("rel", href);
		$(this).find(".action").remove();
	}).live("click", function(){
		window.location = $(this).attr("rel");
	});
});
