$(document).ready(function() {
  $("#styleswitchers").show();
  $.stylesheetInit();
  /* taken from style_switcher.js */
  var c = readCookie('style');
  if (c) { $.highlightCurrentStylesheet(c); }
  // When one of the styleswitch links is clicked then switch the stylesheet to
  // the one matching the value of that links rel attribute.
  $('.styleswitch').bind('click', function(e) {
    rel = this.getAttribute('rel');
    $.stylesheetSwitch(rel);
    $.highlightCurrentStylesheet(rel);
    return false;
  });
  
  // NAVIGATION
  $('div#nav ul').superfish({
    dropShadows: false,
    hoverClass: 'hover',
    autoArrows: false,
    onInit: function(el) {
      $("div#nav li.current ul").css('visibility','visible').show();
    },
    onHide: function(el) {
      $("div#nav li.current ul").css('visibility','visible').show();
    }
  });
  
  $("td:empty").html("&nbsp;");
  $("th:empty").html("&nbsp;");
    
  // TABLE HOVERING
  $('table.data').tableHover({
    rowClass: 'hoverrow', 
    colClass: 'hover', 
    cellClass: 'hovercell', 
    clickClass: 'click',
    spanRows: false,
    ignoreCols: [1]
  });

  // LINKS
  $("a[rel=blank]").attr('target', '_blank');

  // zoom images
  $('a.zoom').fancybox();
});

// HIGHLIGHT MAPS
var HighlightMap = (function() {
  var current = null,
  timer = null,
  public_functions = {
    highlight: function(area) {
      if (timer) clearTimeout(timer);
      if (current == null) {
        $('#highlight-container').hide().html('<img src="/images/2009/highlights/' + area + '.gif" alt="" />').slideDown();
        current = area;
      } else if (current != area) {
        // $('#highlight-container').slideUp(200, function(){
        //   $(this).html('<img src="/images/2009/highlights/' + area + '.gif" alt="" />');
        // }).slideDown("fast");
        $('#highlight-container').css("height", "176px").html('<img src="/images/2009/highlights/' + area + '.gif" alt="" />');
        current = area;
      }
    },
    out: function() {
      timer = setTimeout(HighlightMap.attenuate, 5000);
    },
    attenuate: function() {
      $('#highlight-container').slideUp();
      current = null;
      timer = null;
    }
  }
  
  return public_functions;
})();

(function($) {
  $.highlightCurrentStylesheet = function(style_name) {
    $("#styleswitchers .styleswitch").html("A");
    $("#styleswitchers ." + style_name).html("[A]");
  }
})(jQuery);

