$("document").ready
(
  function()
  { 
    
    // Add external link popup
    $("#folder_trees li.link > a")
    .click
    (
      function( event )
      {
        event.preventDefault();
        
        window.open( $( this ).attr("href") );
        
        return;
      }
    );
    
    // Add text/image switcher for articles
    $("#content #file .chooser > a")
      .click
      (
        function( event )
        {
          event.preventDefault();
          
          // Click handler for show text action
          if ( $(this).text() == "text" )
          {
            $("#content #file")
              .find(".image")
                .hide()
                .end()
              .find(".text")
                .show()
                .end()
            ;
          }
          
          // Click handler for hide text action
          else
          {
            $("#content #file")
              .find(".image")
                .show()
                .end()
              .find(".text")
                .hide()
                .end()
            ;
          }
          
          // Update current statuses
          $(this)
            .siblings("a")
              .removeClass("current")
              .end()
            .addClass("current")
          ;
          
          return;
        }
      )
    ;
    
    // Make sure to unfocus after clicks (so we can keep keyboard navigation
    // but not annoy mouse users
    $("a").live
    (
      "click",
      function()
      {
        if ( ! $( this ).parents("#nav").size() )
        {
          $(this).trigger("blur");
        }
      }
    );
    
    // Add hover for file nav buttons
    $("#content #nav li.prev a")
      .hover
      (
        function(){ $(this).find("img").attr( "src", _nav_prev_hover ) },
        function(){ $(this).find("img").attr( "src", _nav_prev ) }
      )
      .focus ( function(){ $(this).find("img").attr( "src", _nav_prev_hover ) } )
      .blur  ( function(){ $(this).find("img").attr( "src", _nav_prev ) } )
    ;
    
    // Add hover for file nav buttons
    $("#content #nav li.next a")
      .hover
      (
        function(){ $(this).find("img").attr( "src", _nav_next_hover ) },
        function(){ $(this).find("img").attr( "src", _nav_next ) }
      )
      .focus ( function(){ $(this).find("img").attr( "src", _nav_next_hover ) } )
      .blur  ( function(){ $(this).find("img").attr( "src", _nav_next ) } )
    ;
    
    return;
  }
);
