// ** HOMEPAGE
// ** Helper to vertically-center the tagline paragraphs and fade between them
function fadeTaglineTo(paragraph) {
  // Get the actual height of the paragraph, then pad above/below it
  var padding = Math.floor( (227 - $(paragraph).height()) / 2 );
  $(paragraph).css('padding-top', padding+'px');
  $(paragraph).css('padding-bottom', (padding+1)+'px');

  // In order to get the height of the paragraph, it is initially displayed
  // but invisible. Swap these, so that we can fade it in.
  $(paragraph).css('display', 'none');
  $(paragraph).css('visibility', 'visible');
  $(paragraph).fadeIn(400);

  // Get the next paragraph. Go back to the first if on the last.
  var next_paragraph = $(paragraph).next();
  if(next_paragraph.length == 0) {
    next_paragraph = $('#main_home #intro #tagline p:first');
  }

  // If there's more than one paragraph...
  if($('#main_home #intro #tagline p').size() > 1) {
    // Wait five seconds, fade out the paragraph, then fade in the next
    setTimeout(function(){
      $(paragraph).fadeOut(400, function(){ fadeTaglineTo(next_paragraph); });
    }, 5000);
  }
}


// ** jQuery Listener Events
// ** These actions are binded on page load to existing DOM nodes, and
// ** automatically fire when necessary.
$(function() {

  // ** NAVIGATION
  // ** Superfish dropdowns using jQuery
  // ** http://users.tpg.com.au/j_birch/plugins/superfish/#options
  $('ul#site_nav').superfish({
    hoverClass:  'sfhover',
    pathClass:   '',
    pathLevels:  2,
    delay:       500,
    animation:   {opacity:'show'},
    speed:       500,
    autoArrows:  true,
    dropShadows: true,
    disableHI:   false
  });


  // ** HEADER
  // ** Remove the header's Search Website form's default input text when
  // ** focus shifts to the input. This listener is removed after firing once,
  // ** so the user's actual typed text doesn't dissappear too.

  $('form#search_website_form input#search_website_q').focus(function(event){
    $(this).val('').unbind();
  });


  // ** HOMEPAGE
  // ** Vertically-center the tagline paragraphs, and fade between them
  $('#main_home #intro #tagline p:first').each(function(){
    fadeTaglineTo($(this));
  });


  // ** CONTENT
  // ** Set the paragraph class and related text for inline photos
  $('#content p img').each(function(){
    $(this).parent().addClass('inline_photo');
    $(this).parent().append('<span class="photo_caption">' + $(this).attr('alt') + '</span>');
  });

}); // end jQuery Listener Events

