$(function() {
  $('#toggle-global-search a').click(function() {
    $('#global-search').slideToggle(100);
    $('#toggle-global-search').toggleClass('selected');
    $('#global-search input.query').focus();
  });
  
  function updateContentHeight() {
    var content = $('#content');
    var sidebar = $('#sidebar');
    var footer = $('#footer');
    
    content.height('auto');
    if (content.length > 0 && sidebar.length > 0) {
      var newHeight = Math.max(content.height(), sidebar.height());
      content.height(newHeight);
      footer.css('top', newHeight+100);
    }
  }
  
  if ($.browser.msie) {
    updateContentHeight();
    $(window).resize(updateContentHeight).scroll(updateContentHeight);
  }
  
  if ($.preload) {
    $.preload('img.rollover', {
      find: /\.(gif|jpg|png)/,
      replace: '_hover.$1'
    });
  }
  
  jQuery.fn.extend({
    selfLabel: function() {
      var text = $(this).attr('alt');
      
      function setDefault() {
        if ($(this).val() == '') {
          $(this).addClass('default');
          $(this).val(text);
        }
      }
      
      function removeDefault() {
        if ($(this).val() == text) {
          $(this).removeClass('default');
          $(this).val('');
        }
      }
      
      $(this).focus(removeDefault).blur(setDefault);
      
      $(this).addClass('default');
      $(this).val(text);
    }
  });
  
  $('img.rollover').hover(
    function() {
      if (!$(this).attr('src').match(/_hover/)) {
        $(this).attr('src', $(this).attr('src').replace(/\.(gif|jpg|png)/, '_hover.$1'));
      }
    }, function() {
      $(this).attr('src', $(this).attr('src').replace(/_hover/, ''));
    });
  
  $('ul#primary-nav > li').hover(
    function() {
      $('ul#primary-nav li').removeClass('hover');
      $('ul#primary-nav li.current').addClass('unhover');
      $(this).addClass('hover');
    }, function() {
      $(this).removeClass('hover');
      $('ul#primary-nav li.current').removeClass('unhover');
    });
  
  $('#newsletter-email').selfLabel();
  
  $('#tabbed-info ul#tabs li')
    .hover(function() {
             $(this).animate({ top: '0' }, 100);
           }, function() {
             if (!$(this).hasClass('active')) {
               $(this).animate({ top: '6px' }, 100);
             }
           })
           
    .click(function() {
      $('#tabbed-info ul#tabs li.active').removeClass('active').animate({ top: '6px' }, 100);
      $(this).addClass('active');
      
      $('#tabbed-info .content:visible, #tabbed-info .image:visible').fadeOut();
      
      var show = $(this).children('a').attr('href');
      $(show).fadeIn();
      $(show.replace(/content/, 'image')).fadeIn();
      
      return false;
    });
    
    
});

