function showPic(whichpic) {
  if (!document.getElementById("placeholder")) return true;
  var source = whichpic.getAttribute("href");
  var placeholder = document.getElementById("placeholder");
  placeholder.setAttribute("src",source);
  if (!document.getElementById("description")) return false;
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  var iddescription = whichpic.getAttribute("iddescription");
  for (var i=1; i<6; i++) {
    if (document.getElementById("description" + i)) {
	  document.getElementById("description" + i).style.display= 'none';
	}
  }
  if (document.getElementById(iddescription)) {
    document.getElementById(iddescription).style.display= 'inline';
  }
  //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;
  if (!document.getElementById("thumbBox")) return false;
  var gallery = document.getElementById("thumbBox");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {        
  	preload_image = new Image();
    preload_image.src = links[i].getAttribute("href");
    links[i].onclick = function() {
      return showPic(this);
	  }
	  links[i].onmouseover = function() {
      return showPic(this);
	  }
  }
}

//function addLoadEvent(func) {
//  var oldonload = window.onload;
//  if (typeof window.onload != 'function') {
//    window.onload = func;
//  } else {
//    window.onload = function() {
//      oldonload();
//      func();
//    }
//  }
//}
//
//addLoadEvent(prepareGallery);

$(document).ready(function(){
  prepareGallery()
  
});
