ObjectManager.load("/css/photoviewer.css");

var PhotoViewer = {
	hide: function(e) {
		Innecto.style.set(Innecto.$("photoviewer-overlay"), "display", "none");
		Innecto.style.set(
				Innecto.$("photoviewer-photowrapper"),
				"display",
				"none");
		var IMG = Innecto.$("photoviewer-photo-body").lastChild;
		IMG.src = "";
		Innecto.style.set(IMG, "visibility", "hidden");
		e.preventDefault();
	},
	initialize: function() {
		Array.forEach(arguments, function(el) {
			Array.forEach(el.getElementsByTagName("a"), function(el) {
				EventManager.add(el, "click", PhotoViewer.show);
			});
		});
		document.body
				.insertAdjacentHTML(
						"afterBegin",
						"<div id=\"photoviewer-overlay\"></div><div id=\"photoviewer-photowrapper\"><div id=\"photoviewer-photo\"><div id=\"photoviewer-photo-top-left\"></div><div id=\"photoviewer-photo-top-repeat\"></div><div id=\"photoviewer-photo-top-right\"></div><div id=\"photoviewer-photo-contentwrapper\"><div id=\"photoviewer-photo-content\"><a href=\"#\" id=\"photoviewer-photo-close\"></a><div id=\"photoviewer-photo-body\"><img></div></div></div><div id=\"photoviewer-photo-bottom-left\"></div><div id=\"photoviewer-photo-bottom-repeat\"></div><div id=\"photoviewer-photo-bottom-right\"></div></div></div>");
		EventManager.add(
				Innecto.$("photoviewer-photo-close"),
				"click",
				PhotoViewer.hide);
		EventManager.add(
				Innecto.$("photoviewer-photo-body").lastChild,
				"load",
				function() {
					Innecto.style.set(this, "visibility", "visible");
				});
	},
	show: function(e) {
		Innecto.style.set(Innecto.$("photoviewer-overlay"), "display", "block");
		Innecto.style.set(
				Innecto.$("photoviewer-photowrapper"),
				"display",
				"block");
		Innecto.style.set(
				Innecto.$("photoviewer-photowrapper"),
				"top",
				document.documentElement.scrollTop + "px");
		Innecto.$("photoviewer-photo-body").lastChild.src = this.href;
		e.preventDefault();
	}
};
