var gThumbnailsContainerID = "thumbnails";
var gMainImageContainerID = "mainImageOutline";
var gSlideShowControlsContainerID = "transport";
var gThumbViewer = null;
var gImageViewer = null;
var gSlideShowControl = null;
function InitializeGallery()
{
	gThumbViewer = new Spry.Widget.ThumbViewer(gThumbnailsContainerID);
	gImageViewer = new Spry.Widget.ImageViewer(gMainImageContainerID);
	gSlideShowControl = new Spry.Widget.SlideShowControl(gSlideShowControlsContainerID);
	gThumbViewer.addObserver(function(notificationType, notifier, data)
	{
		if (notificationType == "onSelect")
			gImageViewer.setImage(data);
	});

	gImageViewer.addObserver(function(notificationType, notifier, data)
	{
		if (notificationType == "onPreUpdate")
			gSlideShowControl.killTimer();
		else if (notificationType == "onPostUpdate")
		{
			if (gSlideShowControl.isActive())
				gSlideShowControl.startTimer();
		}
	});

	gSlideShowControl.addObserver(function(notificationType, notifier, data)
	{
		if (notificationType == "onNextSlide")
			gThumbViewer.next();
		else if (notificationType == "onPreviousSlide")
			gThumbViewer.previous(true);
		else if (notificationType == "onFirstSlide")
			gThumbViewer.first(true);
		else if (notificationType == "onLastSlide")
			gThumbViewer.last(true);
	});

	Spry.$$("#thumbnails a, #transport .previousBtn, #transport .nextBtn").addEventListener("click", function(e) { gSlideShowControl.stop(); }, "false");

	var currentLink = gThumbViewer.getCurrentThumbLink();
	if (currentLink)
		gImageViewer.setImage(currentLink.href);
}
