       theme_advanced_blockformats : "p,pre,h1,h2,h3",
       width: '100%',
       height: '400px',
-      setup : HTMLEditingDescriptor.setupTinyMCE,
+      setup : @setupTinyMCE,
       # Cannot get access to tinyMCE Editor instance (for focusing) until after it is rendered.
       # The tinyMCE callback passes in the editor as a paramter.
       init_instance_callback: @focusVisualEditor
     })
 
     @showingVisualEditor = true
-    @element.on('click', '.editor-tabs .tab', this, @onSwitchEditor)
+    # Doing these find operations within onSwitchEditor leads to sporadic failures on Chrome (version 20 and older).
+    $element = $(element)
+    @$htmlTab = $element.find('.html-tab')
+    @$visualTab = $element.find('.visual-tab')
 
-  @setupTinyMCE: (ed) ->
+    @element.on('click', '.editor-tabs .tab', @onSwitchEditor)
+
+  setupTinyMCE: (ed) =>
     ed.addButton('wrapAsCode', {
       title : 'Code',
       image : '/static/images/ico-tinymce-code.png',

    @focusVisualEditor(visualEditor)
    @showingVisualEditor = true

  focusVisualEditor: (visualEditor) ->
    visualEditor.focus()

  getVisualEditor: (element) ->
    ###
    Returns the instance of TinyMCE.
    This is different from the textarea that exists in the HTML template (@tiny_mce_textarea.
    ###
    return tinyMCE.get($(element).find('.tiny-mce').attr('id'))

  save: ->
    @element.off('click', '.editor-tabs .tab', @onSwitchEditor)
    text = @advanced_editor.getValue()
    visualEditor = @getVisualEditor(@element)
    if @showingVisualEditor and visualEditor.isDirty()
      text = visualEditor.getContent({no_events: 1})
    data: text

      lineWrapping: true
    })

    @$advancedEditorWrapper = $(@advanced_editor.getWrapperElement())
    @$advancedEditorWrapper.addClass(HTMLEditingDescriptor.isInactiveClass)

#   This is a workaround for the fact that tinyMCE's baseURL property is not getting correctly set on AWS
#   instances (like sandbox). It is not necessary to explicitly set baseURL when running locally.
