 searchLimitIncreasing = false
+
+currentSearchQueryCount = ->
+  (Session.get('currentSearchQueryCountPublications') or 0) + (Session.get('currentSearchQueryCountPeople') or 0)
 
 Deps.autorun ->
   # Every time search query is changed, we reset counts

  Session.get 'currentSearchQueryCountPeople'

Template.noResults.noResults = ->
  Session.get('currentSearchQueryReady') and not Session.get('currentSearchQueryCountPublications') and not Session.get('currentSearchQueryCountPeople')

Template.resultsLoad.loading = ->
  Session.get('currentSearchQueryLoading')

Template.resultsLoad.more = ->
  Session.get('currentSearchQueryReady') and Session.get('currentSearchLimit') < (Session.get('currentSearchQueryCountPublications') or Session.get('currentSearchQueryCountPeople') or 0)

Template.resultsLoad.events =
  'click .load-more': (e, template) ->

  $(window).off 'scroll.results'

increaseSearchLimit = (pageSize) ->
  if searchLimitIncreasing
    return
  if Session.get('currentSearchLimit') < currentSearchQueryCount()
    searchLimitIncreasing = true
    Session.set 'currentSearchLimit', (Session.get('currentSearchLimit') or 0) + pageSize

