 module.exports.HomeView = class HomeView extends Backbone.View
   events:
     'click #main-layout-search-bar-container': 'highlightSearch'
+    'mousedown #main-layout-search-bar-button': 'trackClickingSearch'
     'blur #main-layout-search-bar-container': 'unhighlightSearch'
     'click #main-layout-search-bar-button': 'performSearch'
 


  highlightSearch: (e, onlyOnFocus = true) ->
    if onlyOnFocus
      $('#home-foreground #main-layout-search-bar-container').addClass('focused') if @$input.is(':focus')
    else
      $('#home-foreground #main-layout-search-bar-container').addClass('focused')

  unhighlightSearch: (e) ->
    $(e.currentTarget).removeClass('focused')

  isEmpty: ->
    _.isEmpty(_s.trim(@$input.val()))

  performSearch: (e) ->
    e.preventDefault()
    return if @isEmpty()
    term = @$input.val()
    window.location = "/search?q=#{term}"



  setupSearchBar: ->
    @$input = @$('#home-foreground #main-layout-search-bar-input')
    @$searchContainer = $('#home-foreground #main-layout-search-bar-container')
    @searchBarView = new SearchBarView
      el: @$searchContainer
      $input: @$input
      displayEmptyItem: true
      autoselect: true
