   else
     obj[key]
 
-avgKey = (arr, key, args...) ->
-  sum = 0
-  for item in arr
-    sum += result(item, key, args...)
-
-  sum / arr.length
-
 class Bar
   constructor: ->
     @progress = 0

  constructor: (request) ->
    @progress = 0

    size = null
    request.onprogress = =>
      try
        headers = request.getAllResponseHeaders()

        for name, val of headers
          if name.toLowerCase() is 'content-length'
            size = +val
            break

      catch e

      if size?
        # This is not perfect, as size is in bytes, length is in chars
        try
          @progress = request.responseText.length / size
        catch e
      else
        # If it's chunked encoding, we have no way of knowing the total length of the
        # response, all we can do is incrememnt the progress with backoff such that we
        # never hit 100% until it's done.
        @progress = @progress + (100 - @progress) / 2

    request.onload = request.onerror = request.ontimeout = request.onabort = =>
      @progress = 100

class ElementMonitor
  constructor: (selectors...) ->


do init = ->
  sources = [new AjaxMonitor, new ElementMonitor('body'), new DocumentMonitor, new EventLagMonitor]
  
  bar = new Bar

  # Each source of progress data has it's own scaler to smooth its output
  scalers = []

  # We have an extra scaler for the final output to keep things looking nice as we add and
  # remove sources
  uniScaler = new Scaler

reset = ->
  bar.destroy()

  # Not all browsers support cancelAnimationFrame
  cancelAnimation = true

  if animation?
    cancelAnimationFrame? animation
    animation = null

  init()
