addLoadEvent(initImg);

/*
 *	This function initializes all img elements that are part
 *	of the gallery and adds an onclick event, which in turn
 *	calls the showPic function.
 */
function initImg() {
	if (!document.getElementsByTagName) {
		return false;
	}
	
	var links = document.getElementsByTagName("a");
	for (var i = 0; i < links.length; i++) {
		if (links[i].className == "imgLink") {
			links[i].onclick = function () {
				return showPic(this);
            		}
		}
	}
}

/*
 *	This function displays the image associated with
 *	the link in the placeholder area.
 */
function showPic(link) {
	var imgFrame = document.getElementById("imgFrame");
	var oldGalleryImg = document.getElementById("galleryImg");

	// Create an image element called placeholder
	var galleryImg = document.createElement("img");
	galleryImg.setAttribute("id", "galleryImg");
	galleryImg.setAttribute("src", link.getAttribute("href"));
	galleryImg.setAttribute("alt", "");

	// Replace the content of the 'imgFrame' div with the gallery image
	imgFrame.replaceChild(galleryImg, oldGalleryImg);

	return false;
}

function toggleOn(artist, img, on) {
	if (on) {
		document.images[img].src = "galleries/" + artist + "/thumb/" + img + "_on.jpg";
	} else {
		document.images[img].src = "galleries/" + artist + "/thumb/" + img + ".jpg";
	}
}
