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

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



  highlightSearch: (e, onlyOnFocus = true) ->
    if onlyOnFocus
      @$searchContainer.addClass('focused') if @$input.is(':focus')
    else
      @$searchContainer.addClass('focused')

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

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

  trackClickingSearch: (e) ->
    @clickingSearch = true

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

