function showPic(whichpic) {
  if (!document.getElementById("viewing")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("viewing");
  placeholder.setAttribute("src",source);
  if(whichpic.getAttribute("jwidth")) {
  	if(whichpic.getAttribute("jwidth") == "narrow") {
		placeholder.style.marginTop = 20+"px";
	}
	else if(whichpic.getAttribute("jwidth") == "wide") {
		placeholder.style.marginTop = 100+"px";
	}
	else if(whichpic.getAttribute("jwidth") == "special") {
		placeholder.style.marginTop = 174+"px";
	}
  }
  if (!document.getElementById("description")) return false;
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  var description = document.getElementById("description");
  if (description.firstChild.nodeType == 3) {
    description.firstChild.nodeValue = text;
  }
  return false;
}

function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  addHookToGallery("thumbnails1");
  addHookToGallery("thumbnails2");
  addHookToGallery("thumbnails3");
  addHookToGallery("thumbnails4");
  addHookToGallery("thumbnails5");
}

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

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

addLoadEvent(prepareGallery);