/* All images listed in galleryImages variable should open in a gallery window when clicked */
function initGallery() {
	if (!galleryImages) return;
	
	var links = document.getElementsByTagName('a');
	
	for (var i=0; i<links.length; i++) {
		var a = links[i];
		
		var checkHref = a.href.replace(/https\:\/\//, 'http://');
		
		if (!a.href || !galleryImages[checkHref]) {
			continue;
		}
		
		a.fullWidth = galleryImages[checkHref].width;
		a.fullHeight = galleryImages[checkHref].height;
		a.onclick = showFullGalleryImage;
	}
}

function showFullGalleryImage() {
	var x, y, url, width, height, ah;
	height = this.fullHeight + 20;
	width  = this.fullWidth + 30;

	if(height > screen.availHeight-30) {
		ah = screen.availHeight-30
	} else {
		ah=height;
	}
	if (screen.availHeight-height > 100) {
		y = (screen.availHeight-height)/5
	}
	
	x = (screen.width/2)-(width/2)
	if (x < 0) {
		x=0
	}

	url = "/showpic.php?img=" + escape(this.href);
	
	var win = window.open(url, 'galleryImage', 'scrollbars=1,resizable=1,width=' +width+ ',height=' + ah + ",top=" + y + ",left=" + x);
	win.focus();
	
	return false;
}

