function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false; 
  if (!document.getElementById("gallery")) return false; 
  var gallery = document.getElementById("gallery");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
    }
  }
}

function showPic(whichpic) {
  if (!document.getElementById("default")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("default");
  if (placeholder.nodeName != "IMG") return true;
  placeholder.setAttribute("src",source);
  if (!document.getElementById("description")) return false;
  var text = whichpic.getAttribute("title") ?
    whichpic.getAttribute("title") : "";
  var description = document.getElementById("description");
  if(description.firstChild.nodeType == 3) {
    description.firstChild.nodeValue = text;
  }
  return false;
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(prepareGallery);









