         $("#logs .spinner").stop(true, true).fadeOut ->
           $("#logs .refresh, #logs .clear").show()
 
+  toggleMemory:(e) ->
+
+    if $('#memorypanel').hasClass('hidden')
+      $('#memorypanel').removeClass 'hidden'
+    else
+      $('#memorypanel').addClass 'hidden'
+
   clearMemory: (e) ->
 
     if confirm("Are you sure you want to clear memory of this Agent?")

    $(".agent-show #show-tabs a[href='#logs'], #logs .refresh").on "click", @fetchLogs
    $(".agent-show #logs .clear").on "click", @clearLogs
    $(".agent-show #memory .clear").on "click", @clearMemory

    # Trigger tabs when navigated to.
    if tab = window.location.href.match(/tab=(\w+)\b/i)?[1]
      if tab in ["details", "logs"]
        $(".agent-show .nav-pills li a[href='##{tab}']").click()

    $('#toggle-memory').click ->
      if $('#memorypanel').hasClass('hidden')
        $('#memorypanel').removeClass 'hidden'
      else
        $('#memorypanel').addClass 'hidden'

  fetchLogs: (e) ->
    agentId = $(e.target).closest("[data-agent-id]").data("agent-id")

        .fail ->
          $("#memory .spinner").fadeOut ->
            $("#memory .clear").css(display: 'inline-block')

            
$ ->
  Utils.registerPage(AgentShowPage, forPathsMatching: /^agents\/\d+/)
