$(document).ready(function(){
	
	var form = $('#mailinglist-remove').html();
	
	$('#callback').click(function(e){
		$('#contactform-inner').slideToggle('medium', function() {
			if ($(this).css("display") == 'block') {
				$("a#callback").css('background-image','url(/images/close.gif)');
			} else {
				$("a#callback").css('background-image','url(/images/open.gif)'); 
			}			
		});
		
		e.preventDefault();
	});
	
	$("#quickcontact").validate({
		submitHandler: function() { postdata(); }
	});
	
	$("#sayhello").validate();
	$("#workwithus").validate();
	$("#joinourteam").validate();
	
	$("#mailinglist").validate({
		submitHandler: function() { postmailapi(); }
	});
	
	$("div.blog-post:last-child").addClass("noborder");
	$("li.comment:last-child").addClass("noborder");

	$('#anotheremail').click(function(){
		$('#mlthankyou').toggle();
		var a = $('#mailinglist-remove').html(form);
		a.fadeIn('slow');
		return false;
	});

	$(".image a").hover(function() {
		$(this).stop().animate({"opacity": "0.7"}, "slow");
	}, function() {
		$(this).stop().animate({"opacity": "1"}, "slow");
	});


});

/* Quick Form */
function postdata() {
	$.post('/includes/email/email-callback.php', $("#quickcontact").serialize(), successful());
}
function successful() {
	$('div#contact-remove').html('');
	$('#wait').fadeIn('slow');
	setTimeout(sent(), 2000);
}
function sent() {
	$('#wait').fadeOut('slow');
	setTimeout(thankyou(), 1000);
}
function thankyou() {
	$('#thankyou').fadeIn('slow');
	setTimeout(slideup(), 2000);
}
function slideup() {
	$('#contactform-inner').slideToggle('medium');
	$("a#callback").css('background-image','url(/images/open.gif)');
}

/* Mailing List API */
function postmailapi() {
	$.post('/includes/mailinglist.php', $("#mailinglist").serialize(), successfulapi());
}
function successfulapi() {
	$('#mailinglist-remove').html('');
	$('#mlwait').fadeIn('slow');
	setTimeout(curld(), 2000);
}
function curld() {
	$('#mlwait').fadeOut('slow');
	setTimeout(thankyouapi(), 1000);
}
function thankyouapi() {
	$('#mlthankyou').fadeIn('slow');
}
