 
 (($) ->
 
-  $('.fields select[name="field[as]"]').live 'change', ->
+  #----------------------------------------------------------------------------
+  # Custom field tabs switcher
+  $(document).on "click", "*[data-tab-class]", (event) ->
+    event.preventDefault()
+    $el = $(this)
+
+    $(".fields").each ->
+      $(this).hide()
+
+    $(".inline_tabs ul li").each ->
+      $(this).removeClass "selected"
+
+    klass = $el.data("tab-class")
+    $("#" + klass + "_section").show()
+    $el.addClass "selected"
+
+  #----------------------------------------------------------------------------
+  # Load custom field subform
+  $(document).on 'change', '.fields select[name="field[as]"]', ->
     $.ajax(
         url: '/admin/fields/subform?' + $(this).parents('form').serialize()
         dataType: 'html'

    )
    false

  $('.edit_field a.close, .edit_field a.cancel').live 'click', ->
    $(this).closest('.edit_field').hide()
    false

  false

) jQuery

    field_group.find('.create_field').slideDown().find('input[name="field[label]"]').focus()
    false

  #----------------------------------------------------------------------------
  # Close new field form
  $(document).on 'click', '.create_field a.close, .create_field a.cancel', ->
    $(this).closest('.create_field').hide()
    $(this).closest('.field_group').find('.create .arrow').html(crm.COLLAPSED)
    false

  #----------------------------------------------------------------------------
  # Edit an existing field
  $(document).on 'click', '.fields a.edit', ->
    $('.edit_field').hide()
    $.ajax(
        url: $(this).attr('href')
