
function galleryInit()
{
	if(location.href.lastIndexOf('#') > 0) {
		var number = Number(location.href.slice(location.href.lastIndexOf('o') + 1));
	} else {
		var number = 1;
	}
	showImage(number);
	addPhotoLinks(document.getElementById('thumbnails'))
}

function showImage(number)
{
	var photoDiv = document.getElementById('photo');
	for(var i = 0, count = 1, len = photoDiv.childNodes.length; i < len; i++) {
		var node = photoDiv.childNodes[i];
		if(node.nodeName == 'DIV') {
			if (count == number) {
				node.className = 'show';
			} else {
				node.className = 'hide';
			}
			count++;
		}
	}
}

function addPhotoLinks(node)
{
	for(var i = 0, len = node.childNodes.length; i < len; i++) {
		var childNode = node.childNodes[i];
		if (childNode.nodeName == 'A') {
			if(childNode.addEventListener) 
				childNode.addEventListener('click', photoLink, false);
			else if (childNode.attachEvent)
				childNode.attachEvent('onclick', photoLink);
			else childNode.onclick = photoLink;
				
		} else {
			if (childNode.childNodes) addPhotoLinks(childNode);
		}
	}
}

function photoLink(e)
{
	var e = e || window.event;
	var t = e.target || e.srcElement;
	var a = t.parentNode;
	showImage(a.href.slice(a.href.lastIndexOf('o') + 1));
}

if(window.addEventListener)
	window.addEventListener('load', galleryInit, false);
else if (window.attachEvent) 
	window.attachEvent('onload', galleryInit);
else
	window.onload = galleryInit;