$(function() {
  var familyList = $('#family dl');
  var familyLinks = $("#family dt a");
  
  familyLinks.click(function(e) {
    e.preventDefault();
    
    if ($(this).hasClass('expanded')) {
      $(this).removeClass('expanded');
      familyList.removeClass('open').find('dd:visible').slideUp();
      familyList.find('.intro').slideDown();
      $('#family img.photo').hide();
      $('#family-photo').show();
    } else {
      var id = $(this).attr('href');
      
      familyLinks.removeClass('expanded');
      $(this).addClass('expanded');
    
      familyList.addClass('open').find('dd:visible').slideUp();
      $(id).slideDown();
      
      $('#family img.photo').hide();
      $(id + '-photo').show();
    }
    
    return false;
  });
  
  $('#contact-form').ajaxForm({
    beforeSubmit: function(arr, form) {
      $('input, textarea, select', form).attr('disabled', 'disabled');

      $('.loading', form).show();
      $('.submit input', form).css('opacity', '0.6');
    },
    
    success: function(response, status, xhr, form) {
      form.clearForm();
      
      $('input, textarea, select', form).removeAttr('disabled');

      $('.loading', form).hide();
      $('.submit input', form).css('opacity', '1.0');
      
      alert("Thank you for contacting us. We'll be in touch soon.");
    }
  });
  
  
  if (typeof window.orientation !== 'undefined') {
    function setHeight() {
    	document.getElementById('page').style.height = window.innerHeight + 'px';
    }
    
    setHeight();
    $(window).bind('orientationchange', setHeight);
    
    var scroller = new iScroll('content');
    
    $('a').click(function(e) {
      var href = $(this).attr('href');
      
      if (href[0] == '#' && !$(this).is('#family .detail a')) {
        scroller.scrollToElement(href);
        return false;
      }
    });
  } else {
    $.localScroll({
      hash: true,
      easing: 'easeOutExpo',
      filter: ':not(#family .detail a)'
    });
  }
});

