function previewPic(animage) {
  if (!document.getElementById("imagepreview")) return true;
  var source = animage.getAttribute("href");
  var imagepreview = document.getElementById("imagepreview");
  imagepreview.setAttribute("src",source);
  return false;
}
function setupPictures() {
  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].onhover = function() {
      return previewPic(this);
	}
    links[i].onmouseover = links[i].onhover;
  }
}

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

