 
   updateDisplay = ->
     if !localStorage.lastSyncTime?
-      localStorage.lastSyncTime = new Date().toISOString()
-      localStorage.num          = 0
-      localStorage.total        = 0
-      localStorage.releases     = '[]'
+      initLocalStorage()
       syncCollection(1)
     else
       prettyDate = $.timeago Date.parse localStorage.lastSyncTime

  $('#sync-collection').on 'click', (event) ->
    $(this).text('Syncing...')
    $(this).attr('disabled', true)
    localStorage.lastSyncTime = new Date().toISOString()
    localStorage.num          = 0
    localStorage.total        = 0
    localStorage.releases     = '[]'
    updateDisplay()
    syncCollection(1)


$ ->
  initLocalStorage = ->
    localStorage.lastSyncTime = new Date().toISOString()
    localStorage.num          = 0
    localStorage.total        = 0
    localStorage.releases     = '[]'

  syncCollection = (page) ->
    $.get '/collection/sync',
      { page: page },
