document.observe('dom:loaded', function() {

  // Turn obfuscated email spans into links...
  var spans = $$('span.em_obf');
  spans.each(function(span) {
    var content = span.removeChild(span.firstChild);
    var link = new Element('a', {href: '#contact'});
    link.appendChild(content);
    span.appendChild(link);
  });

  // ...and deal with the email links when clicked

  document.observe('click', function(event) {
    var email = event.element().up('.em_obf');
    if (email) {
      var adr = 'mailto:';
      $A(email.firstChild.firstChild.childNodes).each(function(c) {
        if (c.nodeType == 3) adr += c.nodeValue;
        else adr += ($(c).hasClassName('em_obf_a') ? '@' : '.');
      });
      window.location = adr;
      event.stop();
    }
  });

});

if (window.IE55OR6) {
  Event.observe(window, 'load', function() {
    // Fix PNGs on load rather than dom:loaded because IE6 goes almost understandably weird
    // if we try to set width/height before img has loaded and these dimensions are available

    $$('img').each(function(img) {
      if (img.src.substring(img.src.length - 10, img.src.length).toLowerCase() != "-trans.png" || img.hasClassName('skip_ie_fix')) return;
      var style = img.style.cssText + '; display: inline-block; width: ' + img.width + 'px; height: ' + img.height + 'px; ';
      style += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "', sizingMethod='scale'); ";
      if (img.parentElement.href) style += 'cursor: hand; ';
      var span = new Element('span', { title: img.title || img.alt, style: style });
      span.id = img.id;
      span.className = img.className;
      img.replace(span);
    });
  });
}

