Event.observe(window, 'load', preloadImages);

function preloadImages() {
  $$('img[large]').each(function(img) {
    img.lrg = document.createElement('img');
    img.lrg.src = img.getAttribute('large');
    img.lrg.style.display = 'none';
    img.parentNode.appendChild(img.lrg);
  });
}

function showImage(img, active_id) {
  var lrg = $('placeholder');
  if ($(active_id)) { $(active_id).id = null; }
  img.id = active_id;
  new Effect.Opacity(
    lrg,
    {
      duration: 0.15,
      from: 1.0,
      to: 0.0,
      afterFinish: function () {
        lrg.onload = function () { new Effect.Opacity(lrg, {duration: 0.2}); }
        lrg.src = img.getAttribute('large');
      }
    }
  );
}
