     @get_svg_canvas().getSvgString() (data, error) =>
       @svg_annotation_data = data
       $svg = $(data)
-
       @$sb_svg_src.show();
       w = $svg.attr('width')
       h = $svg.attr('height')

  set_image_source: (src) ->
    @last_src = @current_src unless @current_src == ""
    @current_src = src
    @$current_src_field.val(src)
    @update_display()

  set_image:(html) ->

          canv.recheckBrowserFeatures()
    })

    @$snapshot_button   = $("#{@form_sel} .take_snapshot")
    @$edit_button       = $("#{@form_sel} .edit_answer")
    @$done_button       = $("#{@dialog_sel} .image_done_button")
    @$cancel_button     = $("#{@dialog_sel} .image_cancel_button")
    @$svg_form          = $("#{@dialog_sel} form")

    @$delete_button     = $("#{@dialog_sel} .image_delete_button")
    @$replace_button    = $("#{@form_sel} .replace_snapshot")
    @$undo_button       = $("#{@dialog_sel} .image_reset_button")

    @$saved_response    = $("#{@form_sel} .answer_text")
    @$text_response     = $("#{@dialog_sel} .text_response textarea")

    @$drawing_button    = $("#{@form_sel} .drawing_button")

    @$thumbnail         = $("#{@form_sel} .snapshot_thumbnail")
    @$displayed_answer  = $("#{@form_sel} .answer_text")

    @$image_url_field = $("#{@form_sel} [name=\"#{@form_prefix}[image_url]\"]")
    @$annotated_image_url_field = $("#{@form_sel} [name=\"#{@form_prefix}[annotated_image_url]\"]")


    @current_thumbnail  = @get_current_thumbnail()

    @current_src        = @$image_url_field.val()
    @create_snapshot_shutterbug()
    @create_svg_shutterbug()
    @create_hooks()
    @update_display()
  
  get_current_thumbnail: ->
    @$annotated_image_url_field.val() ||  @$image_url_field.val()

  create_hooks: ->
    @$snapshot_button.click =>
      @last_svg = ' '
      @shutterbug.getDomSnapshot()
      @show()

    @$drawing_button.click =>
      # Same as snapshot, but without taking the snapshot.
      @last_svg = ' '
      @set_svg_background()
      @show()

    @$replace_button.click =>
      @replace_snapshot()

    @$edit_button.click =>
      # Save @last_svg so cancel will work
      @last_svg = sketchily_decode64(@$annotation_field.val())
      @show()
      @set_svg_background()

    @$cancel_button.click =>
      @last_svg = ' ' unless @last_svg
      @reset_image()
      @clear_text_response()
      @hide()

    @$done_button.click =>
      @save()

    @$undo_button.click =>
      @reset_image()

    @$svg_form.on('ajax:success', (e, data, status, xhr) =>
      # update at least the answer perhaps the thumbnail
      # we might also want to delay the closing the dialog until this happens
      @$displayed_answer.html(data.answer_html)
    ).bind 'ajax:error', (e, xhr, status, error) =>
      # don't update the answer and possibly revert the thumbnail if it was
      # updated
      # should show "<p>ERROR</p>" somewhere
      # if the form is still open it would make sense to put the error there

  create_snapshot_shutterbug: ->
    @shutterbug       = new Shutterbug(@interactive_selector, null,(image_tag)=>
      @set_image(image_tag)
    ,@image_question_id)

  create_svg_shutterbug: ->
    @shutterbug_svg  = new Shutterbug(@sb_svg_src, null,(image_tag)=>
      @set_svg_input(image_tag)
      @submit_svg_form()
