//equal height box plugin
(function($) { 
$.fn.equalHeight = function(options) {
  var opts = $.extend({}, $.fn.equalHeight.defaults, options);
  var maxHeight = opts.minHeight; 
  this.each(function(){
    var minHeight = $(this).css('min-height');
    maxHeight = (minHeight.match(/px/) && parseInt(minHeight) > maxHeight) ? parseInt(minHeight) : maxHeight;
    maxHeight = $(this).height() > maxHeight ? $(this).height() : maxHeight;
  });   
  return this.each(
  function(){ 
  $(this).height(maxHeight + 'px'); }); };
  $.fn.equalHeight.defaults = {
    minHeight: 0
  };
$.rot13 = function(string) {
    var newString = string;
    if (typeof string === 'string') {
      newString = newString.replace(/[a-z0-9]/ig, function(chr) {
          var cc = chr.charCodeAt(0);
          if (cc >= 65 && cc <= 90) cc = 65 + ((cc - 52) % 26);
          else if (cc >= 97 && cc <= 122) cc = 97 + ((cc - 84) % 26);
          else if (cc >= 48 && cc <= 57) cc = 48 + ((cc - 43) % 10); //rot5 for numerals
          return String.fromCharCode(cc);
      });
    }
    return newString;
}
})(jQuery);



function setActiveLinks() {
  var path = window.location.pathname;
  path = path.replace(/index.html/, '');

  $('#nav a').each(function(i) {
    var target = $(this).attr('href').replace(/index.html/, '');
    if ((path.indexOf(target) != -1 && target.length <= path.length && target != '/') || target == path) {
      var activeClass = i== 0 ? "firstActive" : "active";
      $(this).parent().addClass(activeClass);
    }
  });
  $('#subnav a').each(function(i) {
    var target = $(this).attr('href').replace(/index.html/, '');
    if ((target.indexOf('/about/archive') != -1 && path.indexOf('/about/archive') != -1 && target.length <= path.length) || target == path) {
      $(this).addClass('active');
    }
  });

}

$(document).ready(function(){
  setActiveLinks();
  if (jQuery.browser.msie && (jQuery.browser.version < 7)) {
   $('body').addClass('ie6');
   $('#logo img:first').attr('src', '/images/logo.gif');
   $('#searchBtn').attr('src', '/images/search-btn.gif');
  }
  $("#nav ul li").not(':first').mouseenter(function(){
    $(this).addClass('hover');
  }).mouseleave(function(){
    $(this).removeClass('hover');
  });
  $('#nav ul li:first').mouseenter(function(){
    $(this).addClass('firstHover');
  }).mouseleave(function(){
    $(this).removeClass('firstHover');
  });
  $('.triBlockWrapper .triBlock').equalHeight();
  $('#search').focusin(function(){
    if ($(this).val() == "Search") {
      $(this).val('');
    }
  }).focusout(function(){
    if ($(this).val() == '') 
      $(this).val('Search')
  });
  $('a.email').each(function(){
    var newMail = $.rot13($(this).attr('href').replace('mailto:', ''));
    $(this).attr('href', 'mailto:'+newMail);
  });
  $('span.email').each(function(){
    var newMail = $.rot13($(this).text());
    $(this).empty().append(newMail);
  });
});