function scrollAnimation() {
  //Animates scrolling to anchor links. Thanks Karl Swedberg. http://www.learningjquery.com/2007/10/improved-animated-scrolling-script-for-same-page-links
	$('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}, 900);
	    return false;
	   }
	  }
	  }); 
}

function catDisplayer() {
  //Makes dropdown Category selector
  var catList = $("ul.categories");
  
  $(catList).hide();

  //toggle the components with class hidden-content and adds open-content-displayer class to corresponding head
  $("h3.categorizer").click(function() 
  {
    $(this).toggleClass("open-categorizer");
    $(this).next(catList).slideToggle(200);
  });
  $('body').click(function() 
  {
    $(catList).hide();
  });
}

$(function() {  

	$('a').not('.anchor').click(function() 
  {
    $('body').fadeOut();
  });


  //jQuery backed CSS3 support for IE
  $('input[type=hidden]').hide(); 
  
  //Enhancements to contactForm in Footer
  $('form#contactForm').submit(function() {
		$('form#contactForm .error').remove();
		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 button').fadeOut('normal', function() {
        $(this).parent().append('');
      });
      var formInput = $(this).serialize();
      $.post($(this).attr('action'), formInput, function(data){
      $("form#contactForm").before('<p class="thanks"><strong>Thanks!</strong> Your message was successfully sent.</p>');
      });
      $("form#contactForm").slideUp("fast",function() {});
    }

		return false;

	});
	
	//Animates form labels
	$('form .slider label').each(function(){
	var labelColor = '#666';
	var restingPosition = '5px';

	// style the label with JS for progressive enhancement
	$(this).css({
		  'color' : labelColor,
		 	'position' : 'absolute',
	 		'top' : '6px',
			'left' : restingPosition,
			'display' : 'inline',
    	'z-index' : '99'
	});

	// grab the input value
	var inputval = $(this).next('input, textarea').val();
	var textareaval = $(this).next('textarea').val();

	// grab the label width, then add 5 pixels to it
	var labelwidth = $(this).width();
	var labelmove = labelwidth + 5;

	//onload, check if a field is filled out, if so, move the label out of the way
	if(inputval !== ''){
		$(this).stop().animate({ 'left':'-'+labelmove }, 1);
	}    	

	// if the input is empty on focus move the label to the left
	// if it's empty on blur, move it back
	$('input, textarea').focus(function(){
		var label = $(this).prev('label');
		var width = $(label).width();
		var adjust = width + 5;
		var value = $(this).val();

		if(value == ''){
			label.stop().animate({ 'left':'-'+adjust }, 'fast');
		} else {
			label.css({ 'left':'-'+adjust });
		}
	  
	  }).blur(function(){
		var label = $(this).prev('label');
		var value = $(this).val();
		if(value == ''){
			label.stop().animate({ 'left':restingPosition }, 'fast');
			}
		});
});

});



