jQuery(document).ready( function($) {
  
  // Form labels
  $('#sidebar .wpcf7 label').click( function() {
    $(this).hide().parent().find('input').css({zIndex: 15}).focus();
  });
  $('#sidebar .wpcf7 input').focus( function() {
    $(this).css({zIndex: 15})
            .parents('.form-item').find('label').hide(); // this is for the benefit of IE7
  });
  $('#sidebar .wpcf7 input').blur( function() {
    if ( $(this).val() == '' ) {
      $(this).css({zIndex: 5})
            .parents('.form-item').find('label').show(); // this is for the benefit of IE7
    }
  });
  
  
  // Community page image gallery
  $('.community-gallery .gallery-item:first-child').addClass('active');
  $('.community-gallery .thumbnail img').click( function() {
    if ( !$(this).parents('.gallery-item').hasClass('active') ) {
      $(this).parents('.community-gallery').find('.gallery-item.active')
              .removeClass('active')
              .find('.thumbnail img').fadeTo(250, 0.55).end()
              .find('.large').fadeOut(250);
      $(this).fadeTo(250, 1)
              .parents('.gallery-item').addClass('active')
              .find('.large').fadeTo(250, 1);
    }
  });
  
  // Collapsible divs
  $('.collapsible').addClass('collapsed').each( function() {
    $(this).children(':not(h3:eq(0))').wrapAll('<div class="collapsible-wrapper"></div>').end()
          .children('.collapsible-wrapper').hide().end()
          .children('h3').css({cursor:'pointer'})
            .click( function() {
              $(this).siblings('.collapsible-wrapper').slideToggle();
              $(this).parent().toggleClass('collapsed');
            });
  });
  
  $('.person').css({height: 'auto'}).each( function() {
    if ( $(this).prev('.person').length == 0 || $(this).prev('.person').css('clear') != 'left' ) {
      $(this).css({clear: 'left'});
    }
  });
  
  // For IE 6
  $('#content ul.community-gallery li:first-child').addClass('first');
  $('.community-gallery .gallery-item:not(:first-child) .thumbnail img').fadeTo(250, 0.55);
});