//Creates a queue of functions to be executed when the page loads using addLoadEvent(functionName);
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}

//Creates a "selected" class when the thumbnail is clicked.
lyclickMenu = function() {
	var getEls = document.getElementById("ly_views").getElementsByTagName("li");
	var getAgn = getEls;
 
	for (var i=0; i<getEls.length; i++) {
			getEls[i].onclick=function() {
				for (var x=0; x<getAgn.length; x++) {
				getAgn[x].className=getAgn[x].className.replace("selected", "");
				}
				this.className+=" selected";
				}
			}
		}

//Loops through all the links in the image ly_views list and when the link is activated calls the lyshowPic function.
function prepare_lyGallery() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("ly_views")) return false;
	var ly_views = document.getElementById("ly_views");
	var links = ly_views.getElementsByTagName("a");
	for ( var i=0; i < links.length; i++) {
		links[i].onclick = function() {
		return lyshowPic(this);
		}
	links[i].onkeypress = links[i].onclick;
 	}
 }

//Swaps out the ly_gallery image for an image in the linked from the ly_views list.
function lyshowPic(lywhichpic) {
	if(!document.getElementById("ly_gallery")) return true;
	var source = lywhichpic.getAttribute("href");
	var ly_gallery = document.getElementById("ly_gallery");
	ly_gallery.setAttribute("src", source);
	if (!document.getElementById("description")) return false;
	if (lywhichpic.getAttribute("title")) {
		var text = lywhichpic.getAttribute("title");
	} else {
		var text = "";
	}
	return false;
}

// Load functions when the page loads.
addLoadEvent(prepare_lyGallery);
addLoadEvent(lyclickMenu);
