function pollForImageReady(img, polling_url, style) {
  img = $(img)
  $.poll(function(retry) {
    var xhr = $.get(polling_url, { style: style }, function(response, status) {
      status_code = xhr.status
      xhr = null
      if (status_code == 200) {
        img.removeClass('processing')
        img.removeAttr('onload')
        img.attr('src', response)

      // 202 == still processing
      } else if (status_code == 202) {
        retry()
      } else {
        // otherwise, just fail
      }
    })
  })
}

// $(function() {
//    $('img.processing').each(function() {
//      pollForImageReady($(this), $(this).attr('data-status_url'), $(this).attr('data-image_style'))
//    })
// })
