$(document).ready(function() {

  // Shoulder navigation.

  $('div#shoulder-navigation ul li:not(.on)').hover(function() {
    $(this).addClass('hover');
    var currentImage = $(this).find('img');
    currentImage.attr('src', currentImage.attr('src').replace('off.jpg', 'hover.jpg'));
  }, function() {
    $(this).removeClass('hover');
    var currentImage = $(this).find('img');
    currentImage.attr('src', currentImage.attr('src').replace('hover.jpg', 'off.jpg'));
  });

  $('div#shoulder-navigation ul li').click(function() {
    window.location = $(this).find('a').attr('href');
  });

  /* focus types cooser */
  $('div.content div#focuschoicecontainer div#focuschoice ul li:not(.on)').hover(function() {
    $(this).addClass('hover');
    var currentImage = $(this).find('img');
    currentImage.attr('src', currentImage.attr('src').replace('off.jpg', 'hover.jpg'));
  }, function() {
    $(this).removeClass('hover');
    var currentImage = $(this).find('img');
    currentImage.attr('src', currentImage.attr('src').replace('hover.jpg', 'off.jpg'));
  });

  $('div.content div#focuschoicecontainer div#focuschoice ul li').live('click',function() {
    window.location = $(this).find('a').attr('href');
  });

  $('a[rel="facebox"]').facebox();

  $('a#focuschoicelink').click(function(){
    offerFocusAgain();
  })


  function offerFocusAgain()
  {


    $("div#newcss").remove();
    $.get('/css/focus-selector.css',function(newCss){
      $('#footer').append('<div id="newcss"></div>');
      $('#newcss').append('<style type="text/css">'+newCss+'</style>');
    });


     $.facebox.settings.opacity = 0.6;

      $.facebox({
        ajax: '/focus-selector/?' + new Date().getTime()
      });

      // Handle link clicks within the focus selector.
      $('ul#focus-types li').live('click', function() {
        window.location = $(this).find('a').attr('href');
        return false;
      });
  }



  // Feature clicks.

  $('div#features ul li').click(function() {
    var sLoc = $(this).find('a').attr('href');
    var external = $(this).find('a').attr('rel') == 'external' ? 'Y' : 'N';
    if (external=='Y') {
      window.open(sLoc) ;
      return false;
    }else {
      window.location = sLoc
      return false;
    }
  });

  // Equalize category map column heights.

  var maxColumnHeight = 0;

  $('div#categories-map ul.categories li.category').each(function() {
    maxColumnHeight = $(this).height() > maxColumnHeight ? $(this).height() : maxColumnHeight;
  });

  $('div#categories-map ul.categories li.category').each(function() {
    $(this).css('height', maxColumnHeight);
  });

  // Handle external links.

  $('a.external').click(function() {
    window.open($(this).attr('href'));
    return false;
  });

});
