   pluginInit: ->
     # Register the event handlers required for creating a selection
     $(document).bind({
-      "click": @makeSentenceSelection
+      "click": @findASentence
     })
 
     this.operational = false
     this.currentIndex = 0
+    this.currentSentence = 0
     this.storedEvent = null
+    this.extentElement = null
 
     null
 
   destroy: ->
     $(document).unbind({
-      "click": @makeSentenceSelection,
+      "click": @findASentence
     })
     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.
+  anchorToPage: (data) ->
+    anchor = new xpathRange.SerializedRange(data).normalize(document)
+
+    window.getSelection().removeAllRanges()
+    window.getSelection().addRange(anchor.toRange())
+
+    return null
+
+  normalizeStyleTags: (target) ->
+
+    return target
+
+    # 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


    return null


  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)

    selection = Annotator.Util.getGlobal().getSelection()
    ranges = for i in [0...selection.rangeCount]

      target = $(target).parent()
      tagName = $(target).prop("tagName").toLowerCase()

    return target

  packageData: (initialTarget, endTarget, endIndex) ->
    full_xpath = Util.xpathFromNode($(initialTarget), document)
    end_xpath = Util.xpathFromNode($(endTarget), document)

    data = {
      start: full_xpath
      startOffset: this.currentIndex
      end: end_xpath
      endOffset: endIndex + 1
    }

    return data

  selectSentence: (initialTarget, currentTarget = undefined, force = false) ->

    if currentTarget == undefined
        currentTarget = initialTarget

    desiredText = $(currentTarget).text()
    match = /[.!?]/.test(desiredText)
    desiredText = desiredText.split(/[.!?]/)

    offset_to_use = 0
    counter = 0

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

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

    if desiredText.length == 1
      desiredText = $(currentTarget).text()
    else
      desiredText = desiredText[this.currentSentence]

    endIndex = offset_to_use + desiredText.length + this.currentSentence + 1

    if endIndex > $(currentTarget).text().length - 1
      endIndex = $(currentTarget).text().length - 1

    # test if we have found a sentence marker or if we are forcing this through anyway
    if match or force
      data = this.packageData(initialTarget, currentTarget, endIndex)
      this.anchorToPage(data)
    else
      # here want to test:
      # 1. is there a sibling element?
      # 2. is there a parent element with a next sibling?
      nextSibling = $(currentTarget).next()

      if nextSibling != undefined and nextSibling.length != 0
        this.selectSentence initialTarget, nextSibling
      else
        nextSibling = this.findNextJumpNode(currentTarget)

        if nextSibling != undefined and nextSibling.length != 0
          this.selectSentence initialTarget, currentTarget, true
        else
          this.selectSentence initialTarget, nextSibling

  findASentence: (event = {}) =>
    this.storedEvent = event

    this.currentIndex = 0
    this.selectSentence event.target

    selection = Annotator.Util.getGlobal().getSelection()
    ranges = for i in [0...selection.rangeCount]
      r = selection.getRangeAt(0)
      if r.collapsed then continue else r

    if ranges.length
      event.ranges = ranges
      @annotator.onSuccessfulSelection event
      @annotator.createAnnotation()

    return null

  # This is called when the mouse is clicked on a DOM element.
  # Checks to see if there is a sentence that we can select, if so
