$( function() {
  dateAndWeather = $('<div class="date_and_weather" />');
  $('#header_container').append(dateAndWeather);
  date = $('<div class="date">' + Date.today().toString('dddd, MMMM d, yyyy') + '</div>');
  date.appendTo(dateAndWeather).fadeIn(250);

  weather = $('<div class="weather" />').load('/2011_05_refresh/includes/weather.cfm', function(r, s) {
    if (s !== 'error') {
      weather.prependTo(dateAndWeather).fadeIn(250);
    }
  });

/*
* Set up the header's search to show "Search this site..."
*/
  var defaultSearchText = $('#header_search_text > label').text();
  headerSearchInput = $('#header_search_text > input');

  if (!headerSearchInput.val()) {
    headerSearchInput.val(defaultSearchText);
  }

  headerSearchInput
    .focus(function() {
      if (headerSearchInput.val() == defaultSearchText) {
        $(this).val('');
      }
    })
    .blur(function() {
      if (headerSearchInput.val() == '') {
        $(this).val(defaultSearchText);
      }
    });

  $('#primary_navigation > li > a').click(function(e) {
    if ($(this).attr('href') === '#') {
      e.preventDefault();
    }
    $(this).siblings('.further_information').slideDown(500, 'easeOutQuint');
    $(this).parent().addClass('active');
  });

  $('#primary_navigation > li').mouseleave(function() {
    if ($(this).hasClass('active')) {
      $(this).children('.further_information').slideUp(500, 'easeOutQuint', function() {
        $(this).parent().removeClass('active');
      });
    }
  });

  /*
   * Add the ShareThis buttons using Javascript (because it is using invalid XHTML)
   */

  $('#body_container .footer').prepend('\
    <div class="share_this">\
      <span class="st_facebook_button" displayText="Facebook"></span>\
      <span class="st_twitter_button" displayText="Tweet"></span>\
      <span class="st_email_button" displayText="Email"></span>\
    </div>');

  stLight.options({
    publisher:'b771fbfc-3592-4003-a7b0-f75a521c7a9b'
  });

});

