var activeGalleries = new Object();

function initGallery(uid) {
	console.log("init "+uid);
	console.log(activeGalleries[uid]);
	if(typeof activeGalleries[uid] == "undefined") {
		activeGalleries[uid] = 'active';
		var slider = dojo.byId("slider_"+uid);
		
		var offset = 1;
		dojo.query("#"+uid+" table").forEach(function(li){
			if (offset == 1) {
		     dojo.animateProperty({
					node:li,
					easing: function (n){return n*(n-2)*-1;},
					duration: 750,
					delay:0,
					properties: {
						marginTop: 20
					}
				}).play();
		     offset++;
			} else {
				dojo.animateProperty({
					node:li,
					easing: function (n){return n*(n-2)*-1;},
					duration: 750,
					delay:0,
					properties: {
						marginBottom: 20
					}
				}).play();
			}
		});
		
		dojo.animateProperty({
			node:slider,
			easing: function (n){return n*(n-2)*-1;},
			duration: 600,
			properties: {
				marginTop: 174
			}
		}).play();
		dojo.animateProperty({
			node:slider,
			easing: function (n){return n*(n-2)*-1;},
			duration: 600,
			delay: 400,
			properties: {
				left: -400
			}
		}).play();
		dojo.query("#"+uid+" .galleryThumbTable").forEach(function(li){
		     dojo.animateProperty({
					node:li,
					easing: function (n){return n*(n-2)*-1;},
					duration: 750,
					delay:300,
					properties: {
						width: 400
					}
				}).play();
		});
	}
}

function click2(sender, uid) {
	gallerySlideIn(uid, sender.getAttribute('filepath'));
}

function gallerySlideIn(uid, newImagePath) {
	var wrapper = dojo.byId("slide_wrapper_"+uid);
	var delay = 350;
	if (wrapper.hasChildNodes()) {
		var fadeArgs = {
	            node: wrapper.childNodes[0],
	            duration: 500,
	            onEnd: function() {
					wrapper.removeChild(wrapper.childNodes[0]);
					var element = dojo.create("div")
					dojo.style(element, "position", "relative");
					dojo.style(element, "height", "300px");
					dojo.style(element, "width", "210px");
					dojo.style(element, "opacity", 0);
					dojo.style(element, "overflow", "hidden");
					var image = dojo.create("img");
					image.src = newImagePath;
					dojo.place(image, element);
					dojo.place(element, wrapper);
					var fadeArgs = {
				            node: element,
				            duration: 500,
				        };
				    dojo.fadeIn(fadeArgs).play();
				}
	        };
	    dojo.fadeOut(fadeArgs).play();
		delay = 700;
	} else {
		var element = document.createElement("div");
		dojo.style(element, "position", "relative");
		dojo.style(element, "height", "300px");
		dojo.style(element, "width", "210px");
		dojo.style(element, "opacity", 0);
		dojo.style(element, "overflow", "hidden");
		
		var image = document.createElement("img");
		image.src = newImagePath;
		dojo.place(image, element);
		
		dojo.place(element, wrapper);
		var fadeArgs = {
	            node: element,
	            duration: 500,
	            delay:600
	        };
	    dojo.fadeIn(fadeArgs).play();
	}
	
}
