﻿var GalleryContainer = null;
function ShowGallery(index) {

	if (!GalleryContainer) {
		GalleryContainer = $("GalleryContainer");
		GalleryContainer.Content = $("GalleryContent");
		GalleryContainer.setStyles({
			'display': 'none'
		});
		$("CloseGalleryLink").addEvent('click', function() {
			GalleryContainer.setStyle('display','none');
		});
	}

	var ws = window.getSize();
	var w = ws.x - 40;
	var h = ws.y - 20 - 43;
	var wp = window.getScroll();

	GalleryContainer.setStyles({
		'width': w,
		'height': h + 53,
		'top': wp.y + 10,
		'left': wp.x + 10
	});

	GalleryContainer.Content.empty();
	GalleryContainer.Content.adopt(new Swiff('Swf/Viewer.swf', {
		width: w,
		height: h,
		id: 'viewer',
		vars: {
			'xmlDataPath': "Images/Gallery/GallerySimple.xml",
			'preloaderColor': '0xffffff',
			'firstImageIndex': index
		}
	}));





	GalleryContainer.setStyle('display','block');

}

function LoadThumbnails() {

	var requestGallery = new Request({
		autoCancel: true,
		method: 'get',
		secure: true
	});

	var thiz = this;

	requestGallery.addEvent('onSuccess', function(responseText, responseXML) {

		var Right = $("Right");
		Right.empty();

		var xml = responseXML.documentElement;
		var filenames = xml.getElementsByTagName("filename");
		var imagePathPrefix = xml.getAttribute("thumbPath");  //"Images/Gallery/small/1/";

		for (var i = 0; i < filenames.length; i++) {
			var filename = filenames[i].firstChild.nodeValue;
			var a = new Element("a", {
				'href': 'javascript:void(0);'
			});
			var image = new Element("img", {
				'src': imagePathPrefix + filename,
				'alt': ''
			});
			a.index = i;
			a.addEvent('click', function() {
				thiz.ShowGallery(this.index);
			});
			a.adopt(image);
			a.inject(Right);
		}

		//alert(Right.get('html'));
		//alert(filenames.length);

	});

	requestGallery.setOptions({ url: "Images/Gallery/GallerySimple.xml?date=" + new Date() });
	requestGallery.send();
	
}


