ScrollOut({
  threshold: 0.4,
  cssProps: {
    viewportY: true,
    visibleY: true
  }
});

$( document ).ready(function() {

  var result = $('#result');

  $('#mailer').submit(function(e){
    e.preventDefault();

    result.removeClass("error").text("");

    $.ajax({
      method: "POST",
      url: "/assets/php/mailer.php",
      data: $(this).serialize(),
    }).done(function(data){
      if(data=="success"){
        result.text("Message Sent, I'll get back to you ASAP!");
        $('#mailer')[0].reset()
      } else {
        result.addClass("error").text(data);
      }
    }).fail(function(error){
      result.text("There was an error sending your message... Please try again!").addClass("error");
    });
  });

  $("a").on('click', function(event) {
    if (this.hash !== "") {
      event.preventDefault();
      var hash = this.hash;

      $('html, body').animate({
        scrollTop: $(hash).offset().top
      }, 500, function(){
        // window.location.hash = hash;
      });
    }
  });
  $('.parallax').parallax();
});
