// onload routines
(function($) {
  $(function(){
    // fix top navigation borders
    $("#header_nav ul").find("li:last").addClass("last");
    $("#header_nav ul").find("li:first").addClass("first");

    // initialize drop-down menus
    $("ul.sf-menu").superfish({
      delay: 0,
      speed: "fast"
    });
  
    // HACK: SuperFish isn't really designed to support images for menu items, and it doesn't set CSS classes for hardly any elements upon hover.
    //       For text links, a:hover can adjust the styling, but the :hover pseudoselector isn't supported on anything but anchor tags in IE6/IE7.
    //       Thus, we replace "off." with "on." in all background-image styles upon hover.
    $('.sf-menu li').hover(
      function() { $(this).css('background-image', $(this).css('background-image').replace('off.', 'on.')); },
      function() { $(this).css('background-image', ''); }
    );

    // set search form parameters
    var DEF_VAL = "Search";
    var search = $('#headerSearch input[name=q]');
    if (search.length > 0) {
      search.focus(function() {
        $(this).css('background', ''); /* Override Google CSE trying to nerf the background. */
        if ($(this).val() == DEF_VAL)
          $(this).val('');
      });
      search.blur(function() {
        $(this).css('background', ''); /* Override Google CSE trying to nerf the background. */
        if ($(this).val() == "")
          $(this).val(DEF_VAL).css('background', '');
      });
    }

    // set external links
    $("a[@href^=http]").each(function () {
      if(this.href.indexOf(location.hostname) == -1) {
        $(this).attr("target", "_blank");
      }
    });
  });
})(jQuery);

