 
         else
           currentMenuItem =
-            index: contentHeaders.length - 1,
-            url: "#" + $(contentHeaders.last()).attr("id")
+            index: 0
+          return getPrevMenuItem()
       else if currentMenuItem.index <= 0
         prev = $(".js-last-page")
 

          return getNextMenuItem()

        else
          currentMenuItem =
            index: 0,
            url: "#" + $(contentHeaders[0]).attr("id")

      else if currentMenuItem.index + 1 >= contentHeaders.length
        next = $(".js-next-page")


$ ->
  currentMenuItem = null
  anchor_selector = ".markdown-body h3,
    .markdown-body h4,
    .markdown-body h5,
    .markdown-body h6"
  contentHeaders = $(anchor_selector)
  if anchors
    anchors.options =
      placement: "right",
      icon: "#"
    anchors.add(anchor_selector)

  $(document).on "click", ".js-nav-item", (e) ->
    e.preventDefault()
    $("body").toggleClass("is-nav-close is-nav-open")

  $(document).on "keypress", (e) ->

    pushHash = (item) ->
      if item
        window.location = item.url
