// make proper email addresses

(function() {
  var a = ['r'].reverse().join('') + '@' + window.location.hostname, b = document.createElement('a'), c = document.getElementById('e');
  b.appendChild(document.createTextNode(a));
  b.href = ['o','t','l','i','a','m'].reverse().join('') + ':' + a;
  c.replaceChild(b, c.firstChild);
})();


// Create navigation from H2 elements on page
(function() {
  var h2 = document.getElementsByTagName('h2'),
      ul = document.createElement('ul'),
      hl = document.getElementById('homelink'),
      h3 = hl.appendChild(document.createElement('h3')),
      i = 0, j = h2.length, li, a, txt, h3;
  for (; i < j; i++) {
    li = ul.appendChild(document.createElement('li'));
    a = li.appendChild(document.createElement('a'));
    txt = h2[i].firstChild.nodeValue;
    a.appendChild(document.createTextNode(txt));
    txt = txt.split(' ')[0];
    a.href = '#' + txt.toLowerCase();
    h2[i].id = txt.toLowerCase();
  }
  ul.className = 'homelink';
  h3.appendChild(document.createTextNode('On this page:'));
  hl.appendChild(ul);
})();