 $ ->
+  initLocalStorage = ->
+    localStorage.lastSyncTime = new Date().toISOString()
+    localStorage.num          = 0
+    localStorage.total        = 0
+    localStorage.releases     = '[]'
+
   syncCollection = (page) ->
     $.get '/collection/sync',
       { page: page },


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

  $('#sync-collection').on 'click', (event) ->
    $(this).text('Syncing...')
    $(this).attr('disabled', true)
    initLocalStorage()
    updateDisplay()
    syncCollection(1)

