   @doesUriMatch: (uri) ->
     uri.path.match(PATTERN)?
   
-  loadThumbnailImage: ->
-    @setThumbnailImage 'images/camera.png'
+  loadPreview: ->
+    @setPreviewImage 'images/camera.png'
 
 window.Media = Media;
    @scrapers.push scraper
  
  loadMedia: (message, link) ->
    container = $('.media', message)
    uri       = new Uri link.href
    
    for scraper in @scrapers
      if scraper.doesUriMatch uri
        break if new scraper(container, link, uri).scrape()

class Media.Scraper
  THROBBER_URI  = 'images/throbber.gif'
  LOADING_TITLE = 'loading\u2026'
  
  @doesUriMatch: (uri) -> false
  
  constructor: (container, link, @uri) ->
    @container = $(container)
    @source    = $(link)
    
    @isCancelled = false
  
  scrape: ->
    try
      @container.append @createDefaultThumbnail()
      @loadThumbnail()
    catch ex
      @cancel()
    
    not @isCancelled
  
  cancel: ->
    @thumbnail.remove()
    @isCancelled = true
  
  loadThumbnail: ->
    @loadThumbnailTitle()
    @loadThumbnailImage()
    @loadThumbnailLink()
  
  loadThumbnailTitle: ->
    @setThumbnailTitle @source.text()
  
  loadThumbnailImage: ->
    null
  
  loadThumbnailLink: ->
    @setThumbnailLink @source[0].href
  
  setThumbnailTitle: (title) ->
    @thumbnailLink.attr title: title
    @thumbnailImage.attr alt: title
  
  setThumbnailImage: (uri) ->
    @thumbnailImage.attr src: uri
  
  setThumbnailLink: (uri) ->
    @thumbnailLink.attr href: uri
  
  createDefaultThumbnail: ->
    @thumbnailImage = $('<img>')
                      .attr(src: THROBBER_URI, alt: LOADING_TITLE)
    @thumbnailLink  = $('<a>')
                      .attr(href: @uri, title: LOADING_TITLE)
    @thumbnail      = $('<div>')
                      .addClass('media-item')
                      .append(@thumbnailLink.append @thumbnailImage)

class YouTubeScraper extends Media.Scraper
  Media.register this
  
  @doesUriMatch: (uri) ->

    else
      uri.host is 'youtu.be'
  
  loadPreview: ->
    if @uri.host is 'youtu.be'
      id = uri.path.substring 1
    else
