$(document).ready(function() {
    // Determine what story is initially up (1-5)
    var featUp = '#' + $("#jt_feats > div:not(.none)").attr('id');
    var firstID = featUp.substring(9);
    var thumbUp = '#jt_thumb_'+firstID;

    // set the initial thumbnail     
    $(thumbUp + ' span.s').css("display", "inline");
    
    $("li[id^=jt_thumb_]").click(function(event){
        var thumbNext = '#' + $(this).attr('id');
        var idNext   = thumbNext.substring(10);
        var featNext  = '#jt_feat_' + idNext;
        if (thumbUp != thumbNext) {
            $(thumbUp + ' span.s').css("display","none");
            $(thumbNext + ' span.s').css("display","inline");
            $(featUp).hide();
            $(featNext).show();
            thumbUp=thumbNext;
            featUp=featNext;
        }
    });

    $("#jt_thumbs ul li img").hoverIntent({
        sensitivity: 7, 
        interval: 200, 
        over: function() {$(this).fadeTo(500,0.5)},
        timeout: 250, 
        out: function() {$(this).fadeTo(250,1)}
    });

    function showThumbText() {
        var textID = '#' + $(this).attr('id') + ' span.t';
        $(textID).css("display","inline");
    }

    function hideThumbText() {
        var textID = '#' + $(this).attr('id') + ' span.t';
        $(textID).css("display","none");
    }
    
  // Left tray behaviors

  var trayBusy=false;  // ignored for now
  var trayStart=false; // trayStart=true when someone has moused over the tray or ul prior to, during, or while expanding, to prevent auto-collapse

  // hover over a li
  $("#tray ul li:not(.sel)").hoverIntent({
      sensitivity: 21, 
      interval: 200, 
      over: function(){$(this).addClass("hover")}, 
      timeout: 250, 
      out: function(){$(this).removeClass("hover")}
  });

  function trayExpand()   {$("#tray ul").show("slide", { direction: "left" }, 1000);}
  function trayCollapse() {$("#tray ul").hide("slide", { direction: "left" }, 1000);}

  $("#tray").mouseover( function() {
      if (!trayBusy) {  
          $("#tray").hoverIntent({
              sensitivity: 4, 
              interval: 200, 
              over: trayExpand, 
              timeout: 500, 
              out: trayCollapse
          });
      }
  });

  $("#tray ul").show("slide", { direction: "left" }, 1000,
      function(){
              setTimeout('$("#tray ul").hide("slide", { direction: "left" }, 1000)', 5000, function(){varBusy=false;})
      ;}
  );
  
  if($.browser.msie) {
      setTimeout('trayBusy=false', 7100);
      setTimeout('$("#tray ul").hide("slide", { direction: "left" }, 1000)', 7100);
  }

  
});
