function sendEmail() {
	document.getElementById('sendEmail').value = 'Sending...';
	document.getElementById('sendEmail').disabled = true;
	$.post("include/process.php?type=sendEmail", $("#emailForm").serialize(),
	function(data){
		if(data == '<span style="color: #333;">Thanks for the email!</span>') {
			document.getElementById('emailError').innerHTML = data;
			document.getElementById('emailName').value = 'Your Name';
			document.getElementById('emailEmail').value = 'Your Email';
			document.getElementById('emailContent').value = 'Message';
			document.getElementById('sendEmail').value = 'Send Email';
			document.getElementById('sendEmail').disabled = false;
		} else {
			document.getElementById('emailError').innerHTML = data;
			document.getElementById('sendEmail').value = 'Send Email';
			document.getElementById('sendEmail').disabled = false;
		}
	});
}

$(document).ready(function() {			   
	$('#navigation a').hover(function(){
		$(this).stop().animate({
			borderWidth: "3px"
		}, 200);
	}, function(){
		$(this).stop().animate({
			borderWidth: "1px"
		}, 200);
	});
	
	$('.boxgrid').hover(function(){
		$(".cover", this).stop().animate({top:'150px'},{queue:false,duration:200});
		$(this).addClass("boxgridHover");
	}, function() {
		$(".cover", this).stop().animate({top:'187px'},{queue:false,duration:200});
		$(this).removeClass("boxgridHover");
	});
	
	$('#contactForm input[type="text"], #contactForm textarea').addClass("idleField");
	$('#contactForm input[type="text"], #contactForm textarea').focus(function() {
		$(this).removeClass("idleField").addClass("focusField");
		if (this.value == this.defaultValue){ 
			this.value = '';
		}
		if(this.value != this.defaultValue){
			this.select();
		}
	});
	$('#contactForm input[type="text"], #contactForm textarea').blur(function() {
		$(this).removeClass("focusField").addClass("idleField");
		if ($.trim(this.value) == ''){
			this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});
	
	$('#sendEmail').click(function() {
		sendEmail();
	});
	
	$('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
			var $target = $(this.hash);
			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
			if ($target.length) {
				var targetOffset = $target.offset().top;
				$('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});
	
	$("a.portfolioImg").fancybox();
	
	$(".tweet:nth-child(odd), .blogPost:nth-child(odd), #otherPlaces li:nth-child(odd)").addClass("oddItem");	
});