 
 project_is_updated = (p_id, tested_at) ->
   server_time = tested_at
-  # Either a tile or a page
-  client_time = $("#project-tile-#{p_id}").data('tested-at')
-  if ! client_time
-    client_time = $("#project-page-#{p_id}").data('tested-at')  
-  client_time < server_time
+  project     = project_container(p_id)
+  return if ! project
+  project.data('tested-at') < server_time
 
 
 update_project_tile = (p_id) ->
-  return if $("#project-tile-#{p_id}").length == 0
+  return if ! element_exists("#project-tile-#{p_id}")
   console.debug("Updating project #{p_id}...")
   prefix   = $('#path-prefix').data('path-prefix')
   tile_url = prefix + '/ajax/' + "project_tile?project_id=#{p_id}"

POLL_FREQUENCY = 5000  # milliseconds


add_action_to_project_tiles = ->
    $('.project-tile .panel-body, .project-tile .panel-heading, .project-tile .panel-footer').click ->
      # Disabled for some reason I've forgotten. We should
      # re-try turbolinks on these. (RS)

      $("#project-tile-#{p_id} abbr.timeago").timeago();
      $("#project-tile-#{p_id}").hover ->   # TODO: do with CSS only
        $(@).toggleClass( 'project-tile-active' )
      add_click_to_project_tiles()
      )


update_project_page = (p_id) ->
  return if ! element_exists("#project-page-#{p_id}")
  console.debug("Updating project page #{p_id}...")
  prefix   = $('#path-prefix').data('path-prefix')
  tile_url = prefix + '/ajax/' + "project_page?project_id=#{p_id}"
