// Script based on: http://sonspring.com/journal/dom-gallery

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("the_description")) return false;
  if (whichpic.getAttribute("title")) {
    var text = whichpic.getAttribute("title");
  } else {
    var text = "";
  }
  var the_description = document.getElementById("the_description");
  if (the_description.firstChild.nodeType == 3) {
				
    the_description.firstChild.nodeValue = text;
  }
  return false;
}

function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("showcase")) return false;
  var gallery = document.getElementById("showcase");
  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 showPic2(whichpic2) {
  if (!document.getElementById("placeholder2")) return true;
  var source2 = whichpic2.getAttribute("href");
  var placeholder2 = document.getElementById("placeholder2");
  placeholder2.setAttribute("src",source2);
  if (!document.getElementById("the_description2")) return false;
  if (whichpic2.getAttribute("title")) {
    var text2 = whichpic2.getAttribute("title");
  } else {
    var text2 = "";
  }
  var the_description2 = document.getElementById("the_description2");
  if (the_description2.firstChild.nodeType == 3) {
				
    the_description2.firstChild.nodeValue = text2;
  }
  return false;
}

function prepareGallery2() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("showcase2")) return false;
  var gallery2 = document.getElementById("showcase2");
  var links2 = gallery2.getElementsByTagName("a");
  for ( var i=0; i < links2.length; i++) {
    links2[i].onclick = function() {
      return showPic2(this);
	}
    links2[i].onkeypress = links2[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);
addLoadEvent(prepareGallery2);