 
   stopLoading: ->
     @_loading = false
-    @actuallyStopHighlighting()
+    @stopEmphasis()
 
   destroy: ->
     for el in @elements

  highlight:   -> @$elements.addClass('fl-active')
  dehighlight: -> @$elements.removeClass('fl-active')


class Factlink.Fact
  constructor: (id, elems) ->
    @id = id
    @elements = elems

    @highlighter = new Highlighter $(@elements)

    @highlight_temporary highlight_time_on_load

    @balloon_manager = new BalloonManager this,
      mouseenter: => @onFocus()
      mouseleave: => @onBlur()
      click:      => @openFactlinkModal()

    $(@elements)
      .on('mouseenter', (e)=> @onFocus(e))


  highlight_temporary: (duration) ->
    @highlighter.highlight()
    setTimeout (=> @stopEmphasis()), duration

  onBlur: -> @attention_span.neglect()
  onFocus: (e) =>
    if e?
      @balloon_manager.set_coordinates($(e.target).offset().top, e.pageX)
    @attention_span.attend()

  startEmphasis: ->
    @highlighter.highlight()
    @balloon_manager.openBalloon()

  stopEmphasis: =>
    return if @shouldHaveEmphasis()

    @highlighter.dehighlight()
    @balloon_manager.closeBalloon()

  shouldHaveEmphasis: =>
    @attention_span.has_attention() || @_loading

  openFactlinkModal: =>
    @startLoading()
    Factlink.showInfo @id, => @stopLoading()

  startLoading: ->
    @_loading = true
