$(function() {
 $('#contact').submit(function() {
  var inputs = [];
  $(':input', this).each(function() {
    inputs.push(this.name + '=' + escape(this.value));
  })
  jQuery.ajax({
    data: inputs.join('&'),
    url: this.action,
    timeout: 5000,
    error: function() {
      alert('Failed to submit, please try again');
    },
    success: function(r) {
     alert(r);
     if (r.match(/success/)) { 
	    $('#contact').html('<strong>Your message has been sent.</strong>');
	   }
    }
  })
  return false;
 })
});

$(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;
                
            }
            
        }
        
    });
    
});

function clearInput(e) {
  if (e.cleared) { return; }
  e.cleared = true;
  e.value = '';
  e.style.color = '#000';
}
