jQuery(document).ready(function(){

	$('li a.exit').click(function(){
		$('body').fadeOut("slow", function() {
		 window.location = '/works'; });
	});

	$('.logo a').click(function(){
		$('body').fadeOut("slow",function() {
		 window.location = '/'; });
	});


	$('input[type="text"], #contactForm textarea').addClass("idleField");
		$('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();
		}
		});
		$('input[type="text"], #contactForm textarea').blur(function() {
			$(this).removeClass("focusField").addClass("idleField");
			if ($.trim(this.value == '')){
			//this.value = (this.defaultValue ? this.defaultValue : '');
		}
	});

	$('form#contactForm').submit(function() {
		$('form#contactForm .error').fadeOut();
		var hasError = false;
		$('.requiredField').each(function() {
			if(jQuery.trim($(this).val()) == '') {
				var labelText = $(this).prev('label').text();
				$(this).parent().append('<span class="error">You forgot to enter your '+labelText+'.</span>');
				hasError = true;
			} else if($(this).hasClass('email')) {
				var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
				if(!emailReg.test(jQuery.trim($(this).val()))) {
					var labelText = $(this).prev('label').text();
					$(this).parent().append('<span class="error">You entered an invalid '+labelText+'.</span>');
					hasError = true;
				}
			}
		});
		if(!hasError) {
			$('form#contactForm li.buttons').fadeOut('fast',"easeOutQuint", function() {
				$(this).parent().append('<img src="/wp-content/themes/yeedor/images/loading-1.gif" alt="Loading&hellip;" height="31" width="31" />');
			});
			var formInput = $(this).serialize();
			$.post($(this).attr('action'),formInput, function(data){
				$('form#contactForm').slideUp("fast","easeOutQuint", function() {
					$(this).before('<p class="thanks"><strong>Thanks!</strong> Your email was successfully sent. Please expect a reply within 1 - 3 business days. In the meantime, keep checking out this site!</p><p>Be friends with me on Facebook.<br/><a href="http://twitter.com/share">Tweet</a></p>');
				});
			});
		}

		return false;

	});

    $(".page-template-blog-php .post, .page-template-projectspage-php .post").hover(function() {
        $(this).stop().animate({ backgroundColor: "#ffffff"}, 'fast');
        },function() {
        $(this).stop().animate({ backgroundColor: "#F1F1F2" }, 800);
    });
    
    $(".sketch").hover(function() {
        $(this).stop().animate({ backgroundColor: "#333"}, 'fast');
        },function() {
        $(this).stop().animate({ backgroundColor: "#262626" }, 800);
    });

});

