function GalleryShow (img) {
	var fulld = $('#gallery-full');
	var full  = $('#gallery-full .main');
	var fulll = $('#gallery-full .loader');
	var fulln = $('#gallery-full .new');
	
	var onready = function (event) {
		full.css('display', 'block');
		fulll.hide();
		

		if ($(window).width() / $(window).height() <= full.width() / full.height()) {
			if ($(window).width() < full.width() + 200) {
				full.width($(window).width() - 200)
			}
		} else {
			if ($(window).height() < full.height() + 200) {
				full.height($(window).height() - 200)
			}
		}
	}
	
	var onclose = function (event) {
		full[0].onload = null;
		full.hide();
		fulll.css('display', 'block');
		fulld.hide();
	}
	
	
	fulln[0].img = img;
	fulln[0].onclick = function () {
		window.open(this.img, "_blank");
	};
	
	full.attr('src', img);
	
	if (!full[0].complete) {
		full[0].onload = onready;
	} else {
		setTimeout(onready, 1);
	}
	
	fulld.show();
	fulld.click(onclose);
}

var lightbox = new function() {
	this.init = function () {
		var onclick = function (event) {
			if (this.parentNode.tagName == "A") {
 				GalleryShow(this.parentNode.href);
			} else {
 				GalleryShow(this.src);
			}
		}
		
 		var imgs = $("#content a > img.lightbox");
 		for (var i = 0; i < imgs.length; i++) {
 			imgs[i].parentNode.onclick = function () { return false; }
 		}
		
		var imgs = $("#content img.lightbox").click(onclick);
	}
}

$("body").ready(
	function () {
		lightbox.init();
	}
)
