function showGallery(img){
	
	var tbl = img.parentNode;
	
	while(tbl.nodeName != "TABLE")
		tbl = tbl.parentNode;
	
	var imgs = tbl.getElementsByTagName("img");
	var imgIndex = 0;
	
	for(var i = 0; i < imgs.length; i++){
		
		if(img == imgs[i])
			imgIndex = i;
	}
	
	var viewportwidth;
	var viewportheight;
	 
	if (typeof window.innerWidth != 'undefined'){
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	else{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	
	var overlay = document.createElement("div");
	overlay.style.width = "100%";
	overlay.style.height = "100%";
	overlay.style.position = "absolute";
	overlay.style.top = "0";
	overlay.style.left = "0";
	overlay.style.zIndex = "50";
	overlay.style.backgroundColor = "#000000";
	overlay.style.opacity = .6;
	overlay.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=60)';
	
	var galleryImg = document.createElement("img");
	galleryImg.src = imgs[imgIndex].src;
	galleryImg.style.display = "block";
	galleryImg.style.position = "absolute";
	if(galleryImg.width > viewportwidth - 80 && galleryImg.width > galleryImg.height){
		galleryImg.width = viewportwidth - 80;
		galleryImg.style.height = "auto";
	}
	else if(galleryImg.height > viewportwidth - 80){
		galleryImg.height = viewportheight - 80;
		galleryImg.style.width = "auto";
	}
	galleryImg.style.top = ((viewportheight / 2 - galleryImg.height / 2)) + "px";
	galleryImg.style.left = ((viewportwidth / 2 - galleryImg.width / 2)) + "px";
	galleryImg.style.zIndex = "51";
	
	var prev = document.createElement("div");
	prev.style.position = "absolute";
	prev.style.zIndex = "53";
	prev.onclick = prevImage;
	prev.onmouseover = function(){prev.style.display = "block";};
	prev.onmouseout = function(){prev.style.display = "none"};
	if(navigator.appName == "Microsoft Internet Explorer"){
		prev.style.cursor = "hand";
		prev.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/prev.png',sizingMethod='crop')";
	}
	else{
		prev.style.cursor = "pointer";
		prev.style.backgroundImage = "url(/images/prev.png)";
	}
	prev.style.width = "100px";
	prev.style.height = "100px";
	prev.style.display = "none";
	prev.style.top = (parseFloat(galleryImg.style.top) + (galleryImg.height / 2) - 50) + "px";
	prev.style.left = (parseFloat(galleryImg.style.left) + (galleryImg.width / 6) - 50) + "px";
	
	var close = document.createElement("div");
	close.style.position = "absolute";
	close.style.zIndex = "53";
	close.onclick = hideGallery;
	close.onmouseover = function(){close.style.display = "block";};
	close.onmouseout = function(){close.style.display = "none"};
	if(navigator.appName == "Microsoft Internet Explorer"){
		close.style.cursor = "hand";
		close.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/close.png',sizingMethod='crop')";
	}
	else{
		close.style.cursor = "pointer";
		close.style.backgroundImage = "url(/images/close.png)";
	}
	close.style.width = "100px";
	close.style.height = "100px";
	close.style.display = "none";
	close.style.top = (parseFloat(galleryImg.style.top) + (galleryImg.height / 2) - 50) + "px";
	close.style.left = (parseFloat(galleryImg.style.left) + (galleryImg.width / 2) - 50) + "px";
	
	var next = document.createElement("div");
	next.style.position = "absolute";
	next.style.zIndex = "53";
	next.onclick = nextImage;
	next.onmouseover = function(){next.style.display = "block";};
	next.onmouseout = function(){next.style.display = "none"};
	if(navigator.appName == "Microsoft Internet Explorer"){
		next.style.cursor = "hand";
		next.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='/images/next.png',sizingMethod='crop')";
	}
	else{
		next.style.cursor = "pointer";
		next.style.backgroundImage = "url(/images/next.png)";
	}
	next.style.width = "100px";
	next.style.height = "100px";
	next.style.display = "none";
	next.style.top = (parseFloat(galleryImg.style.top) + (galleryImg.height / 2) - 50) + "px";
	next.style.left = (parseFloat(galleryImg.style.left) + (galleryImg.width / 1.2) - 50) + "px";
	
	var left = document.createElement("div");
	left.style.position = "absolute";
	left.style.zIndex = "52";
	left.style.backgroundImage = "url(x.gif)";
	left.onclick = prevImage;
	left.onmouseover = function(){prev.style.display = "block"};
	left.onmouseout = function(){prev.style.display = "none"};
	if(navigator.appName == "Microsoft Internet Explorer")
		left.style.cursor = "hand";
	else
		left.style.cursor = "pointer";
	left.style.width = (galleryImg.width / 3) + "px";
	left.style.height = galleryImg.height + "px";
	left.style.top = galleryImg.style.top;
	left.style.left = galleryImg.style.left;
	
	var middle = document.createElement("div");
	middle.style.position = "absolute";
	middle.style.zIndex = "52";
	middle.style.backgroundImage = "url(x.gif)";
	middle.onclick = hideGallery;
	middle.onmouseover = function(){close.style.display = "block"};
	middle.onmouseout = function(){close.style.display = "none"};
	if(navigator.appName == "Microsoft Internet Explorer")
		middle.style.cursor = "hand";
	else
		middle.style.cursor = "pointer";
	middle.style.width = (galleryImg.width / 3) + "px";
	middle.style.height = galleryImg.height + "px";
	middle.style.top = galleryImg.style.top;
	middle.style.left = (parseFloat(galleryImg.style.left) + parseFloat(middle.style.width)) + "px";
	
	var right = document.createElement("div");
	right.style.position = "absolute";
	right.style.zIndex = "52";
	right.style.backgroundImage = "url(x.gif)";
	right.onclick = nextImage;
	right.onmouseover = function(){next.style.display = "block"};
	right.onmouseout = function(){next.style.display = "none"};
	if(navigator.appName == "Microsoft Internet Explorer")
		right.style.cursor = "hand";
	else
		right.style.cursor = "pointer";
	right.style.width = (galleryImg.width / 3) + "px";
	right.style.height = galleryImg.height + "px";
	right.style.top = galleryImg.style.top;
	right.style.left = (parseFloat(galleryImg.style.left) + parseFloat(right.style.width) * 2) + "px";
	
	document.imgGallery = new Object();
	document.imgGallery.imgs = imgs;
	document.imgGallery.imgIndex = imgIndex;
	document.imgGallery.overlay = overlay;
	document.imgGallery.galleryImg = galleryImg;
	document.imgGallery.prev = prev;
	document.imgGallery.close = close;
	document.imgGallery.next = next;
	document.imgGallery.left = left;
	document.imgGallery.middle = middle;
	document.imgGallery.right = right;
	
	window.onresize = resizeGallery;
	
	document.body.appendChild(overlay);
	document.body.appendChild(galleryImg);
	document.body.appendChild(prev);
	document.body.appendChild(close);
	document.body.appendChild(next);
	document.body.appendChild(left);
	document.body.appendChild(middle);
	document.body.appendChild(right);
}

function hideGallery(){
	
	document.body.removeChild(document.imgGallery.overlay);
	document.body.removeChild(document.imgGallery.galleryImg);
	document.body.removeChild(document.imgGallery.prev);
	document.body.removeChild(document.imgGallery.close);
	document.body.removeChild(document.imgGallery.next);
	document.body.removeChild(document.imgGallery.left);
	document.body.removeChild(document.imgGallery.middle);
	document.body.removeChild(document.imgGallery.right);
}

function prevImage(){
	
	if(document.imgGallery.imgIndex < 1)
		document.imgGallery.imgIndex = document.imgGallery.imgs.length - 1;
	else
		document.imgGallery.imgIndex--;
	
	document.imgGallery.galleryImg.src = document.imgGallery.imgs[document.imgGallery.imgIndex].src;
	resizeGallery();
}

function nextImage(){
	
	if(document.imgGallery.imgIndex > document.imgGallery.imgs.length - 2)
		document.imgGallery.imgIndex = 0;
	else
		document.imgGallery.imgIndex++;
	
	document.imgGallery.galleryImg.src = document.imgGallery.imgs[document.imgGallery.imgIndex].src;
	resizeGallery();
}

function resizeGallery(){
	
	var viewportwidth;
	var viewportheight;
	 
	if (typeof window.innerWidth != 'undefined'){
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	}
	else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0){
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}
	else{
		viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
		viewportheight = document.getElementsByTagName('body')[0].clientHeight;
	}
	
	var galleryImg = document.imgGallery.galleryImg;
	var prev = document.imgGallery.prev;
	var close = document.imgGallery.close;
	var next = document.imgGallery.next;
	var left = document.imgGallery.left;
	var middle = document.imgGallery.middle;
	var right = document.imgGallery.right;
	
	document.body.removeChild(galleryImg);
	galleryImg = document.createElement("img");
	galleryImg.src = document.imgGallery.imgs[document.imgGallery.imgIndex].src;
	galleryImg.style.display = "block";
	galleryImg.style.position = "absolute";
	if(galleryImg.width > viewportwidth - 80 && galleryImg.width > galleryImg.height){
		galleryImg.width = viewportwidth - 80;
		galleryImg.style.height = "auto";
	}
	else if(galleryImg.height > viewportwidth - 80){
		galleryImg.height = viewportheight - 80;
		galleryImg.style.width = "auto";
	}
	galleryImg.style.top = ((viewportheight / 2 - galleryImg.height / 2)) + "px";
	galleryImg.style.left = ((viewportwidth / 2 - galleryImg.width / 2)) + "px";
	galleryImg.style.zIndex = "51";
	document.imgGallery.galleryImg = galleryImg;
	document.body.appendChild(galleryImg);
	
	prev.style.top = (parseFloat(galleryImg.style.top) + (galleryImg.height / 2) - 50) + "px";
	prev.style.left = (parseFloat(galleryImg.style.left) + (galleryImg.width / 6) - 50) + "px";
	
	close.style.top = (parseFloat(galleryImg.style.top) + (galleryImg.height / 2) - 50) + "px";
	close.style.left = (parseFloat(galleryImg.style.left) + (galleryImg.width / 2) - 50) + "px";
	
	next.style.top = (parseFloat(galleryImg.style.top) + (galleryImg.height / 2) - 50) + "px";
	next.style.left = (parseFloat(galleryImg.style.left) + (galleryImg.width / 1.2) - 50) + "px";
	
	left.style.width = (galleryImg.width / 3) + "px";
	left.style.height = galleryImg.height + "px";
	left.style.top = galleryImg.style.top;
	left.style.left = galleryImg.style.left;
	
	middle.style.width = (galleryImg.width / 3) + "px";
	middle.style.height = galleryImg.height + "px";
	middle.style.top = galleryImg.style.top;
	middle.style.left = (parseFloat(galleryImg.style.left) + parseFloat(middle.style.width)) + "px";
	
	right.style.width = (galleryImg.width / 3) + "px";
	right.style.height = galleryImg.height + "px";
	right.style.top = galleryImg.style.top;
	right.style.left = (parseFloat(galleryImg.style.left) + parseFloat(right.style.width) * 2) + "px";
}

