dojo.provide("dojo.gallery");
(function () {
	var d = '<div id="dgWrap"><div id="dgTitle"></div><div id="dgDescription"></div><div id="dgLoading"></div><a id="dgLeft">Previous</a><a id="dgRight">Next</a><img id="dgPhoto" /></div>';
	var c = dojo.coords(document.body, true);
	dojo.place(d, document.body, "append");
	dojo.style("dgWrap", {
		position: "absolute",
		width: "20px",
		height: "20px",
		zIndex: "100",
		background: "white",
		padding: "10px",
		top: "100px",
		left: ((c.w - 20) / 2) + "px",
		display: "none",
		cursor: "pointer"
	});
	dojo.style("dgTitle", {
		position: "absolute",
		top: "-20px",
		left: "0",
		width: "100%",
		height: "20px",
		background: "black",
		color: "white",
		textIndent: "12px",
		lineHeight: "20px"
	});
	dojo.style("dgDescription", {
		position: "absolute",
		bottom: "-30px",
		left: "0",
		width: "100%",
		height: "30px",
		background: "black",
		color: "white",
		textIndent: "12px"
	});
	dojo.style("dgLeft", {
		position: "absolute",
		left: "-60px",
		top: "30%",
		background: "white",
		width: "50px",
		padding: "5px",
		display: "none"
	});
	dojo.style("dgRight", {
		position: "absolute",
		right: "-60px",
		top: "30%",
		width: "50px",
		background: "white",
		padding: "5px",
		display: "none"
	});
	dojo.style("dgPhoto", {
		position: "absolute",
		top: "0px",
		left: "0px",
		width: "100%",
		height: "100%",
		opacity: 0
	});
	dojo.style("dgLoading", {
		position: "absolute",
		right: "0px",
		top: "0px",
		width: "17px",
		height: "17px",
		background: "url(/cssimages/ajax-loader.gif)",
		zIndex: 120,
		opacity: 0
	});
	dojo.connect(dojo.byId("dgWrap"), "onclick", function () {
		dojo.gallery.showing = false;
		dojo.query("#dgWrap").fadeOut({
			duration: 1000,
			onEnd: function () {
				var a = dojo.coords(document.body, true);
				dojo.style("dgWrap", {
					display: "none",
					opacity: "0",
					width: "20px",
					height: "20px",
					left: ((a.w - 20) / 2) + "px"
				});
				dojo.removeAttr("dgPhoto", "src")
			}
		}).play()
	});
	dojo.gallery.showing = false;
	dojo.gallery.galleries = [];
	dojo.gallery.details = [];
	dojo.gallery.showGallery = function (ha, a) {
		var h = dojo.gallery.galleries[ha],
			b = (a) ? h.indexOf(a) : 0;
		if (!dojo.gallery.showing) {
			dojo.gallery.showing = true;
			dojo.style("dgWrap", {
				display: "block",
				opacity: "0",
				width: "0",
				height: "0"
			});
			dojo.query("#dgWrap").anim({
				opacity: 1
			}, 300)
		}
		dojo.query("#dgLoading").fadeIn({
			duration: 200
		}).play();
		var g = new Image;
		g.onload = function () {
			
			if( console && console.log ) {
				console.log( b, dojo.gallery.details[ha][b] );
			}
			
			document.getElementById('dgTitle').innerHTML = dojo.gallery.details[ha][b].title;
			document.getElementById('dgDescription').innerHTML = dojo.gallery.details[ha][b].description._content;;
			
			
			
			var f = dojo.coords(document.body, true);
			dojo.query("#dgPhoto").attr("src", this.src);
			dojo.query("#dgLoading").fadeOut({
				duration: 200
			}).play();
			dojo.query("#dgPhoto").fadeIn({
				duration: 1000
			}).play();
			dojo.query("#dgWrap").anim({
				height: slc.getNaturalHeight(this),
				width: slc.getNaturalWidth(this),
				left: (f.w - (slc.getNaturalWidth(this))) / 2
			})
		};
		g.src = h[b].href
	};
	dojo.extend(dojo.NodeList, {
		gallery: function ( extra_details ) {
			var a = new Date().getTime();
			while (dojo.gallery.galleries[a]) {
				a += 1
			}
			dojo.gallery.galleries[a] = this.attr("gallery", a).connect("onclick", function (b) {
				dojo.gallery.showGallery(dojo.query(this).attr("gallery"), this);
				b.preventDefault()
			});
			dojo.gallery.details[ a ] = extra_details;
		}
	})
})();
