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("txt")) return false;
  
  if( whichpic.getAttribute("name") ) {
  	var text = whichpic.getAttribute("name");
  	if (!document.getElementById('t_'+text)) return false;
  	t = document.getElementById('t_'+text);
  	tclone = t.cloneNode(true)
  	tclone.setAttribute( "id", "t_txt_0" );
  	var txt = document.getElementById("txt");
  	txt.removeChild( txt.firstChild );
  	tclone.style.display = 'block';
  	txt.appendChild( tclone );
  	
  }  
  return false;
}

function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("slideshow")) return false;
  var gallery = document.getElementById("slideshow");
  var links = gallery.getElementsByTagName("a");
  for ( var i=0; i < links.length; i++) {
    links[i].onclick = function() {
      return showPic(this);
	}
	links[i].onmouseover = function() {
      return showPic(this);
	}
  }
  if (!document.getElementById("txt")) return false;
  var txtParent = document.getElementById("txt").parentNode;
  var txts = txtParent.getElementsByTagName("span");
  for ( var i=0; i < txts.length; i++) {
  	var id = txts[i].getAttribute("id");
	if( id.match(/txt_[1-9][0-9]?/) ) {
		txts[i].style.display = 'none';
	}
  }
  t = document.getElementById("t_txt_1");
  tclone = t.cloneNode(true)
  tclone.setAttribute( "id", "t_txt_0" );
  var txt = document.getElementById("txt");
  tclone.style.display = 'block';
  txt.appendChild( tclone );

}

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

addLoadEvent(prepareGallery);


