$(document).ready(function(){
  $(".details").hide();
  
  $(".example").click(function(){
    if ($(this).parent().find(".details:visible").length == 0) {
      $(this).parent().find(".details").show("blind");
    } else {
      $(this).parent().find(".details").hide("blind");
    }
    
    return false;
  });
  
  $('.upBtn a').click(function(){
    $('html, body').animate({scrollTop:0}, 'slow');
    return false;
  });
  
  if (self.document.location.hash.substring(1).length > 0) {
    $("." + self.document.location.hash.substring(1)).find('.example').click();
  }
  
  
  //
  // contact form verification
  //
  $(function() {
    contact = $('#contact_form');
    contact.find('input[type="submit"]').click(function() {
      if(contact.find('input[name="name"]').val() != '') {
        if(contact.find('input[name="email"]').val().match(/^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/i)) {
          if(contact.find('textarea[name="details"]').val() != '') {
            return true;
          } else {
            alert('Please write a message.');
            contact.find('input[name="details"]').focus().select();
          }
        } else {
          alert('Please use a valid email address.');
          contact.find('input[name="email"]').focus().select();
        }
      } else {
        alert('Please supply your name.');
        contact.find('input[name="name"]').focus().select();
      }
      return false;
    });

    // function hideForm() {
    //   contact.find('.fields').animate({height: "0px"}, {queue: false, duration: 500, easing: 'easeInCubic'});
    //   contact.find('fieldset').animate({opacity: "0"}, function() {
    //     contact.find('fieldset').hide();
    //     contact.find('h1').show();
    //   });
    // }
    // 
    // function sendMessage() {
    //   $.ajax({
    //     url: '/php/contact_message.php',
    //     type: 'post',
    //     data: 'name=' + contact.find('input[name="name"]').val() + '&email=' + contact.find('input[name="email"]').val() + '&subject=' + contact.find('input[name="subject"]').val() + '&message=' + contact.find('textarea[name="message"]').val(),
    //     success: function(data) {
    //       if(data == '1') {
    //         hideForm();
    //       } else {
    //         alert('Oh no, an error occured, please try again!');
    //       }
    //     }
    //   });
    // };
  });
});

