function changeImage(theSrc, theRel){
	mainImage = document.getElementById("mainpic");
	mainImage.setAttribute("src", theSrc);
	
	theDescriptions = document.getElementsByTagName("div");
	for (i=0; i<theDescriptions.length; i++){
		theClass = theDescriptions[i].className;
		if (theClass == "description"){
			theID = theDescriptions[i].getAttribute("id");
			if (theID == theRel){ 
				theDescriptions[i].style.display = "block";
			}
			else {
				theDescriptions[i].style.display = "none";
				//alert("should be gone");
			}
		}
	}

}

function prepareGallery(){
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	
	galleryDiv = document.getElementById("gallery");
	theList = galleryDiv.getElementsByTagName("ul");
	theLinks = theList[0].getElementsByTagName("a");

	theDescriptions = document.getElementsByTagName("div");
	for (i=0; i<theDescriptions.length; i++){
		theClass = theDescriptions[i].className;
		if (theClass == "description"){
			theID = theDescriptions[i].getAttribute("id");
			if (theID == "breakfastRoom"){ 
				theDescriptions[i].style.display = "block";
			}
			else {
				theDescriptions[i].style.display = "none";
				//alert("should be gone");
			}
		}
	}
	
	for (j=0; j<theLinks.length; j++){
		theLinks[j].onclick = function(){
			theRel = this.getAttribute("rel");
			theHref = this.getAttribute("href");
			changeImage(theHref, theRel);
			return false;
		}
	}
}


//addEvent() by John Resig
function addEvent( obj, type, fn ){ 
   if (obj.addEventListener){ 
      obj.addEventListener( type, fn, false );
   }
   else if (obj.attachEvent){ 
      obj["e"+type+fn] = fn; 
      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
      obj.attachEvent( "on"+type, obj[type+fn] ); 
   } 
} 

//Run dynamicLayout function when page loads and when it resizes.
	addEvent(window, 'load', prepareGallery);
