(function ($) {
Drupal.behaviors.entity_embed = {
  attach:  function(context) {
    $('.entity-select-dialog .js-button-next').click(function(){
        window.console&&console.log('attaching new form element');
        $('[id^="entity-embed-dialog]"').append("<select id='glossaryCapitalization'><option value='unchanged'>- Select Capitalization -</option><option value='unchanged'>Unchanged</option><option value='lowercase'>Lowercase</option><option value='firstLetter'>First Letter</option><option value='allCaps'>All Caps</option> ");
       
        
    });  
      
      
      
    /*  
    $('.item-list ul li', context).click(function(){
      if ($(this).hasClass("active")) {
            return;
      }
      $('.active .views-field-nid span.field-content').attr("id", 'inactive-nid');
      $('.item-list ul li', context).removeClass('active');
      $('#active-nid').removeAttr('id');
      $('#active-title').removeAttr('id');
      $(this).addClass('active');
      $('.active .views-field-nid span.field-content').attr("id", 'active-nid');
      $('.active .views-field-title span.field-content').attr("id", 'active-title');
      window.parent.currentActiveNid = $('#active-nid').text();
      window.parent.currentActiveTitle = $('#active-title').text();
      window.parent.currentActiveType = $('.active .views-field-type span.field-content').text();
      $('#template-select, .messages--error').remove();
      $('#glossaryCapitalization').remove();
      var typeTemplates = allTypeTemplates[$('.active .views-field-type span.field-content').text()];
      var typeLabels = [];
      typeLabels = allTypeLabels[$('.active .views-field-type span.field-content').text()];
      
      if (typeTemplates.length < 2) {
        window.parent.currentActiveTemplate = typeTemplates[0];
        if (window.parent.currentActiveType == 'glossary_term') {
          $('.active').append("<select id='glossaryCapitalization'><option value='unchanged'>- Select Capitalization -</option><option value='unchanged'>Unchanged</option><option value='lowercase'>Lowercase</option><option value='firstLetter'>First Letter</option><option value='allCaps'>All Caps</option> ");
        };
        return;
      }
      var templateSel = $('<select>').appendTo(this).attr("id", 'template-select');
      templateSel.append($("<option/>", {value: 0, text: "- Select a template -"}));
      $(typeTemplates).each(function(i, val) {
          if (typeLabels && (typeLabels.length > 0)) 
             {
               var label = typeLabels[i];
              }
          else
              {
               var label = val;
              };
          templateSel.append($("<option/>", {value: val, text: label}));
      });
      window.parent.currentActiveTemplate = 0;
      
      $('#template-select').change(function(){
        $('#changeHeightandWidth').remove();
        $('#alignmentSelect').remove();
        $('#captionSelect').remove();
        $('#captionText').remove();
          window.parent.currentActiveTemplate = $('#template-select').val();
          
          if (window.parent.currentActiveTemplate == 'custom_size') {
            $('.active').append("<form id='changeHeightandWidth'>");
            $('#changeHeightandWidth').append("Width (px): <input type='text' id='newWidth'>");
            $('#changeHeightandWidth').append("Height (px): <input type='text' id='newHeight'>");
            $('.active').append("<select id='alignmentSelect'><option value='0'>- Select an Alignment -</option><option value='left'>Left</option><option value='center'>Center</option><option value='right'>Right</option> ");
       $('.active').append("<input type='checkbox' id='captionSelect'><span id='captionText'>Show Caption</span>");
      
          };
        if ((window.parent.currentActiveTemplate == 'full')&&(window.parent.currentActiveType=='image')) {
           $('.active').append("<select id='alignmentSelect'><option value='0'>- Select an Alignment -</option><option value='left'>Left</option><option value='center'>Center</option><option value='right'>Right</option> ");
            $('.active').append("<input type='checkbox' id='captionSelect'><span id='captionText'>Show Caption</span>");
        };
        
      });
    });
    */
  }
}
})(jQuery);