Accordion Set JavaScript: Selection Function

function gtJSUI_selectAccordion() {
  var set = this.getAttribute('data-accord-set');
  var section = this.getAttribute('data-accord-section');

  var accordSet = document.getElementById('gtAccordionSet_' + set);

  if (accordSet) {
    for (var x = 0; x < accordSet.children.length; x++) {
      var toggle = document.getElementById('gtAccordionToggle_' + set + '_' + x);
      var heading = document.getElementById('gtAccordionHeading_' + set + '_' + x);
      var content = document.getElementById('gtAccordionPanel_' + set + '_' + x);

      if (toggle && heading && content) {
        /* If selected content panel is already open, close it */
        if ((x == section) && (content.style.display == 'block')) {
          toggle.children[0].className = 'svg-accordplus';
          toggle.setAttribute('aria-expanded', 'false');
          content.style.display = 'none';

        } else {
          toggle.children[0].className = (x == section ? 'svg-accordminus' : 'svg-accordplus');
          toggle.setAttribute('aria-expanded', (x == section ? 'true' : 'false'));
          content.style.display = (x == section ? 'block' : 'none');
        }
      }
    }
  }
}