   $previewContainer.find("."+file+"-preview").last().append "<br>"
   $previewContainer.find("."+file+"-preview").last().append "<hr>"
 
-  # this code is setting the sort_order everytime  time we upload. It takes care of both scenearios, survey new ands survey edit
+  # this code is setting the sort_order every time we upload. It takes care of both scenearios, survey new ands survey edit
   $($previewContainer).closest('.file-upload-input-button').find("."+file+"-preview, .upload-view-mode:visible").each (idx, element) ->
     $(element).find('.upload-sort-order').val(idx+1)
 

      # implement progress indicator
      $(e.target).siblings('.progress').find(".video-progress-bar").css('width', Math.round((data.loaded * 100.0) / data.total) + '%')

  videoIdx = 0
  $('.cloudinary-fileupload.survey-video-upload').bind 'cloudinarydone', (e, data) ->
    #callback = ->
    $(e.target).siblings('.progress').find('.video-progress-bar').removeAttr("style")
    $(e.target).siblings('.progress').addClass('hidden')
    #setTimeout callback, 1000

    $videoPreviewContainer = $(e.target).siblings('.video-preview-container')
    $videoPreviewContainer.append "<div class='video-preview'>" + $.cloudinary.video(data.result.public_id, format: data.result.format, version: data.result.version, crop: 'fill', width: 350) + "</div>"
    addTexareaForUpload("video", data, videoIdx, $videoPreviewContainer)
    poster = $(e.target).closest(".video-column").find('.video-preview:last').find("video").attr("poster")
    videoIdx += 1

    if data.result.format != "mov" && data.result.format != "mp4"
      $(e.target).siblings('.video-upload-error').append "<p style='color:#d6193d;'> Only MP4 and MOV formats supported</p>"

      # implement progress indicator
      $(e.target).siblings('.progress').find('.document-progress-bar').css('width', Math.round((data.loaded * 100.0) / data.total) + '%')

  $('.cloudinary-fileupload.survey-document-upload').bind 'cloudinarydone', (e, data) ->
    # Im setting the upload's index based on the count of existing attachements
    docCount = $(e.target).closest('.file-upload-input-button').find(".document-preview, .upload-view-mode").length
    if docCount == 0
      docIdx = 1
    else
      docIdx = docCount + 1

    console.log docIdx + " document"

    $(e.target).siblings('.progress').find('.document-progress-bar').removeAttr("style")
    $(e.target).siblings('.progress').addClass('hidden')

    # this if statement sets the pdf file's extension to png for a preview in upload
    # publicId = data.result.public_id
