   dehighlight: -> @$elements.removeClass(@class)
 
 class FactInteraction
-  constructor: (@fact) ->
+  constructor: (elements, @id, @options) ->
     @button_attention = new Factlink.AttentionSpan
       lost_attention:   => @show_button.hide()
       gained_attention: => @show_button.show()

    @attentions_do 'loose_attention'
    @show_button.destroy()

class Factlink.Fact
  constructor: (@id, @elements) ->
    @fact_interaction = new FactInteraction(this)

    @highlighter = new Highlighter $(elements), 'fl-highlight'

    @highlight_temporary highlight_time_on_load

    $(@elements).on 'inview', (event, isInView, visiblePart) =>
      @highlight_temporary(highlight_time_on_in_view) if ( isInView && visiblePart == 'both' )


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

  destroy: ->
    for el in @elements

      wait_for_attention:  delay_before_mouseover_detected
      wait_for_neglection: delay_before_mouseout_detected

    @highlighter = new Highlighter $(elements), 'fl-active'

    @show_button = new Factlink.ShowButton
      mouseenter: => @onFocus()
      mouseleave: => @onBlur()
      click:      => @onClick()

    $(elements).on
      mouseenter: (e) =>
        @onFocus()
        @show_button.setCoordinates($(e.target).offset().top, e.pageX)
      mouseleave: => @onBlur()
      click: => @onClick()

  attentions_do: (action) ->
    for attention in [@button_attention, @highlight_attention]
      attention[action]()

  onClick: (options={}) =>
    @show_button.startLoading()

    @attentions_do 'gain_attention'
    @options.on_click success: =>
      @attentions_do 'loose_attention'

  onFocus: -> @attentions_do 'attend'
  onBlur:  -> @attentions_do 'neglect'
