// global JavaScript functions

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

// image gallery script

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

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

addLoadEvent(prepareGallery);