 
     return null
 
+  findNextJumpNode: (target) ->
+    parent = $(target).parent()
+
+    nextSibling = $(parent).next()
+
+    if nextSibling == undefined
+      return this.findNextJumpNode parent
+
+    else if nextSibling.length == 0
+
+      tagName = $(nextSibling).prop("tagName")
+
+      if tagName != undefined
+        tagName = tagName.toLowerCase()
+
+        if tagName == 'body' or tagName == 'html'
+          return nextSibling
+        else
+          return this.findNextJumpNode parent
+      else
+        return this.findNextJumpNode parent
+
+    return nextSibling
 
   moveToNextSentence: (event) ->
     if this.operational == false
       # we are not in sentence selection mode
       return
 
-    this.currentIndex = this.currentIndex + 1
     currentSelection = window.getSelection()
 
-    this.selectSentence(currentSelection.anchorNode.parentElement)
+    this.currentIndex = currentSelection.extentOffset
+    this.currentSentence = this.currentSentence + 1
+
+    elementToUse = currentSelection.extentNode.parentElement
+
+    if elementToUse.textContent.length <= (this.currentIndex)
+      nextSibling = $(elementToUse).next()
+
+      this.currentIndex = 0
+      this.currentSentence = 0
+
+      # algorithm here is:
+      # 1. check if there is a sibling
+      # 2. if there is no sibling, check the parent
+      # 3. if the parent has a sibling, use that
+      # 4. if the parent has no sibling, pass parent as element to 2
+
+      if nextSibling == undefined or nextSibling.length == 0
+        nextSibling = this.findNextJumpNode(elementToUse)
+
+      elementToUse = nextSibling
+
+    this.selectSentence elementToUse
 
     selection = Annotator.Util.getGlobal().getSelection()
     ranges = for i in [0...selection.rangeCount]

  pluginInit: ->
    # Register the event handlers required for creating a selection
    $(document).bind({
      "click": @makeSentenceSelection
    })

    this.operational = false
    this.currentIndex = 0
    this.storedEvent = null

    null

  destroy: ->
    $(document).unbind({
      "click": @makeSentenceSelection,
    })
    super

  toggleOperation: () ->
    this.operational = not this.operational

  prepareData: (target) ->
    desiredText = $(target).text()
    desiredText = desiredText.split(/[.!?]/)

    offset_to_use = 0
    counter = 0

    if desiredText.length == 1
      desiredText = []
      desiredText.push $(target).text()

    for sentence in desiredText
      if counter == this.currentIndex
        break
      offset_to_use = offset_to_use + sentence.length
      counter = counter + 1

    if desiredText.length == 1
      desiredText = $(target).text()
    else
      desiredText = desiredText[this.currentIndex]

    full_xpath = Util.xpathFromNode($(target), document)

    data = {
      start: full_xpath
      startOffset: offset_to_use + this.currentIndex
      end: full_xpath
      endOffset: offset_to_use + desiredText.length + this.currentIndex + 1
    }

    return data

  secondaryJump: (target) ->
    this.currentIndex = 0
    nextSibling = $(target).next()

    if nextSibling != undefined and nextSibling.length != 0
      this.selectSentence nextSibling
    else
      nextSibling = $($(target).parent()).next()
      this.selectSentence nextSibling

  selectSentence: (target) ->

    if tagName = $(target).prop("tagName") == undefined
      window.getSelection().removeAllRanges()
      return

     # Get the currently selected ranges.
    tagName = $(target).prop("tagName").toLowerCase()

    # this loop checks that we are not within a formatting cell and that we should recurse upwards through parent elements

    this.storedEvent = event

    this.currentIndex = 0
    this.currentSentence = 0
    this.selectSentence event.target

    selection = Annotator.Util.getGlobal().getSelection()
