$(document).ready(function(){
	//Magic magicness. (Believe me, it's all unicorns and a few of those cute little panda bears)
	$("a[href^='#']").click(function(){
		var hash = $(this).attr('href') ;
		if(hash == '#') return false ;

		$('html, body').animate({
			scrollTop: $(hash).offset().top
		},'slow', function(){
			window.location.hash = hash ;
		});
		
		return false;
	}) ;
	
	$('.menu li a').mouseover(function(){
		$(this).animate({
			color: '#4db2fa',
		}) ;
	}) ;
	$('.menu li a').mouseleave(function(){
		$(this).animate({
			color: '#DEDEDE',
		}) ;
	}) ;
	
	$('#contactus-button').click(function(){
		$('#footer-bottom-contactus').slideToggle('normal', function(){
			$('html, body').animate({
				scrollTop: $('#footer-bottom-contactus').offset().top
			},'slow');
		}) ;
		
		return false;
	}) ;
	
	$('#contactus').submit(function(){
		$('#contactus').find('label').css('color', '#b5b6b6') ;
		
		//Simple validation...
		var isValid = true ; //Well, technically we'll have to see about that...
		var required_fields = ['from', 'message'] ;
		for(i in required_fields){
			var field = required_fields[i] ;
			if($('[name='+field+']').val() == ''){
				$('[for='+field+']').css('color', '#c02b20') ;
				isValid = false ;
			}
		}
		
		if(!isValid){
			$('#contactus .required').css('color', '#c02b20') ;
			$('#contactus input[type=submit]').effect('shake', {times:2, distance:5}, 50) ;
			return false ;
		}
		
		$.ajax({
			url: ajaxurl + '?action=contactus',
			data: $('#contactus').serializeArray(),
			type: 'POST',
			success: function(r){
				if(r == 'success'){
					$('#contactus').fadeOut('fast', function(){
						$('p.success').fadeIn('slow', function(){
							$('#footer-bottom-contactus').animate({
								height:'50px'
							}, function(){
								$('html, body').animate({
									scrollTop: $('#footer-bottom-contactus').offset().top
								},'slow');
							}) ;
							
						});
					});
				}
			}
		}) ;
		
		return false; 
		
	}) ;
	
	function bgToDark(){
		$('#footer-bg').animate({
			backgroundColor:'#114b8d'
		}, 3000, function(){
			bgToLight();
		});
	}
	
	function bgToLight(){
		$('#footer-bg').animate({
			backgroundColor:'#227de6'
		}, 3000, function(){
			bgToDark();
		});
	}
	
	bgToDark();
}) ;
