// Contact form submit
function checkForm(theForm) {
	if(theForm.name.value == '' || theForm.email.value == '') {
		var msg = '<div class="error" id="error-msg"><p>Please enter a valid name and email address.</p></div>';
		$('#error-msg').remove();
		$(msg).insertBefore('.col-1').hide().slideDown('fast');
		return false;
	} else {
		return true;
	}
}
// Set up windowshade and form
$(document).ready(function() {
	$('#windowshade-inner').hide();			
	$('#windowshade-tab').click(function() {
		$('#windowshade-inner').slideToggle()
     });
	$('#contact-form').attr('onsubmit', 'return checkForm(this);');
});

// Set up page scrolling
$(document).ready(function(){
  $('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;
      }
    }
  });
});

// Of course this is ugly, but it's the most effective way to stop the flash of visible
// content while the page is loading, get over it.
document.write('<style type="text/css">#windowshade-inner { display:none; }"</style>');
