 # Remove via X in corner
 $(document).on 'click', ('.favorites2-edit-modal-delete-confirm'), (e) ->
   return unless $(e.target).text() is 'Remove work'
-  track.click 'Set Management: Remove from set', inline: false
+  analytics.track 'Set Management: Remove from set', inline: false
 
 # Delete set
 $(document).on 'click', ('.favorites2-edit-modal-init + ' +
                          '.favorites2-edit-modal-delete-container' +
                          'favorites2-edit-modal-delete-confirm'), ->
-  track.click 'Set Management: Delete set'
+  analytics.track 'Set Management: Delete set'
 
 # Privacy switch
 $(document).on 'click', '.favorites2-toggle-public', ->
-  track.click 'Set Management: Make private'
+  analytics.track 'Set Management: Make private'
 $(document).on 'click', '.favorites2-toggle-private', ->
-  track.click 'Set Management: Make public'
+  analytics.track 'Set Management: Make public'
 
 # Slideshow
 $(document).on 'click', '#user-profile-collection-right-slideshow', ->
-  track.click 'Set Management: Slideshow'
+  analytics.track 'Set Management: Slideshow'
 
 # Share set
 $(document).on 'click', '#user-profile-collection-right-share', ->
-  track.click 'Set Management: Share set'+  analytics.track 'Set Management: Share set'

  '.favorites2-collection-list li:not(.is-active)'
].join(','), (e) ->
  addedToSet = true
  track.funnel 'Set Management: Add to set',
    setId: $(e.currentTarget).attr('data-id')
  track.funnel 'Set Management: Successful save'
  # Added to an additional set
  if $(e.currentTarget).siblings().hasClass('is-active')
    track.funnel 'Set Management: Add to set - additional set'

# Removed from set X
$(document).on 'click', [
  '.save-controls-drop-down-menu-item.is-active'
  '.favorites2-collection-list > li.is-active'
].join(','), (e) ->
  track.funnel 'Set Management: Remove from set',
    inline: true
    setId: $(e.currentTarget).attr('data-id')

# Name Create new set
onNewSetInline = (e) ->
  return if e.keyCode and e.keyCode isnt 13
  track.funnel 'Set Management: Name Create new set'
$(document).on(
  'keyup', '.favorites2-collection-list-create input', onNewSetInline
)

    return if ($(e.target).closest(
                 '.favorites2-collection-list-container'
              ).length > 0 and not $(e.target).hasClass('.modal-close'))
    analytics.track 'Set Management: Open menu - dismiss'

# Hover on work
$(document).on 'mouseenter', '.artwork-item', ->
  hoverTimeout = setTimeout ->
    hoverTimeout = null
    analytics.track 'Set Management: Hover on work'
  , 300

# Click remove
$(document).on 'click', '.artwork-item-remove', ->
  clickedSaveControl = true
  analytics.track 'Set Management: Click remove'

# Click favicon
$(document).on 'click', '.overlay-button-save, .circle-icon-button-save', (e) ->
  clickedSaveControl = true
  analytics.track 'Set Management: Click favicon'
  if $(e.target).closest('.save-controls-one-btn-container').length
    listenForMenuDismiss()
  if $(e.target).closest('.save-controls-two-btn-container').length
    analytics.track 'Set Management: Successful save'

# Click set stack
$(document).on 'click', ('.save-controls-two-btn-add-to-collection, ' +
                         '.circle-icon-button-add'), ->
  clickedSaveControl = true
  openedMenu = true
  analytics.track 'Set Management: Click set stack'
  listenForMenuDismiss()

# Dismiss
$(document).on 'mouseleave', '.artwork-item', (e) ->
  return clearTimeout(hoverTimeout) if hoverTimeout
  unless clickedSaveControl
    analytics.track 'Set Management: Hover on work - dismiss'
  clickedSaveControl = false

# Work saved to My Favs
$(document).on 'click', ('.save-controls-drop-down-container ' +
                         '.overlay-button-save, .circle-icon-button-save'), ->
  return unless MODE is 'drop down'
  analytics.track 'Set Management: Work Saved to My Favs'
  analytics.track 'Set Management: Successful save'
  listenForMenuDismiss()

# Added to set X
