function showPic(whichpic)
	{
	if (!document.getElementById("galleryphoto"))return true;
	var source=whichpic.getAttribute("href");
	var galleryphoto=document.getElementById("galleryphoto");
	galleryphoto.setAttribute("src",source);
	if (!document.getElementById("caption"))return false;
	if (!whichpic.getAttribute("title")) return false;
	var text=whichpic.getAttribute("title");
	var caption=document.getElementById("caption");
	caption.firstChild.nodeValue=text;
	return false;
	}
	
function prepareGallery() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("gallery")) return false;
  var gallery = document.getElementById("gallery");
  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();
    }
  }
}

function insertAfter(newElement, targetElement)
	{
	var parent=targetElement.parentNode;
	if (parent.lastChild==targetElement)
		{
		parent.appendChild(newElement);
		}
	else
		{
		parent.insertBefore(newElement, targetElement.nextSibling);
		}
	}
		
function createGallery()
	{
	if (!document.createElement) return false;
	if (!document.createTextNode) return false;
	if (!document.getElementById) return false;
	var gallery=document.getElementById("gallery");
	var defaultphoto=gallery.getElementsByTagName("a")[0].getAttribute("href");
	var image=document.createElement("img");
	var housedescription=document.getElementById("housedescription");
	housedescription.style.height="350px";
	housedescription.style.width="190px";
	image.setAttribute("id","galleryphoto");
	image.setAttribute("src", defaultphoto);
	image.style.height="300px";
	image.style.width="400px";
	image.style.border="#0000FF 1px solid";
	gallery.style.marginRight="35px";
	image.style.marginLeft="10px";
	image.style.cssFloat="right";
	var para=document.createElement("p");
	para.setAttribute("id","caption");
	para.style.textAlign="center";
	var desctext=document.createTextNode("Click the scrollbar to view an image.");
	para.appendChild(desctext);
	para.style.fontSize="13px";
	insertAfter(image, gallery);
	insertAfter(para, gallery);

	}

addLoadEvent(createGallery);
addLoadEvent(prepareGallery);

 	