$(document).ready(function() {

  var ourPeopleSearchFieldDefaultValue = 'People Search';

  // Our People search field auto-populate.

  $('input#our-people-search-field').val(ourPeopleSearchFieldDefaultValue);

  // Our People search field focus.

  $('input#our-people-search-field').focus(function() {
    if ($(this).val() == ourPeopleSearchFieldDefaultValue) {
      $(this).val('');
    }
  });

  $('input#our-people-search-field').blur(function() {
    if ($(this).val() == '') {
      $(this).val(ourPeopleSearchFieldDefaultValue);
    }
  });

  // Our People area field selection.

  $('select#our-people-area-field').change(function() {
    if ($(this).val() != '') {
      window.location = $(this).val();
    }
  });

  // Out People search submission.

  $('div#our-people form').submit(function() {
    if ($('input#our-people-search-field').val() == '' || $('input#our-people-search-field').val() == ourPeopleSearchFieldDefaultValue) {
      $('input#our-people-search-field').val('')
    }
  });

  // Equalize panel heights.

  var maxPanelHeight = 0;

  $('div#homepage-panels div.panel').each(function() {
    if ($(this).height() > maxPanelHeight) {
      maxPanelHeight = $(this).height();
    }
  });

  $('div#homepage-panels div.panel').each(function() {
    $(this).css('height', maxPanelHeight);
  });

  // News & Events toggle.

  $('div#news-and-events h2').click(function() {

    // Unselect / hide current section.

    $(this).parents('div#news-and-events').find('h2').removeClass('selected');
    $(this).parents('div#news-and-events').find('ul').css('position', 'absolute').css('left', '-9999px');

    // Select / display new section.

    $(this).addClass('selected');
    $(this).parents('div.section').find('ul').css('position', 'static').css('left', '0');

  });

  // Our People area field selection.

  $('select#practise-area-picker').change(function() {
    if ($(this).val() != '') {
      window.location = $(this).val();
    }
  });

});
