<!--
GalleryManager = Class.create();
GalleryManager.prototype =
{
	galleryList: null,
	initialize: function(e)
	{
		this.galleryList = new Object();
	},
	
	previousImage: function(gallery)
	{
		if(this.galleryList[gallery] == null)
		{
			this.galleryList[gallery] = new Gallery(gallery);
		}
		
		this.galleryList[gallery].previousImage();
	},
	
	nextImage: function(gallery)
	{
		if(this.galleryList[gallery] == null)
		{
			this.galleryList[gallery] = new Gallery(gallery);
		}
		
		this.galleryList[gallery].nextImage();
	}
}

Gallery = Class.create();
Gallery.prototype = 
{
	moving: false,
	maxImageWidth: null,
	galleryPhotos: null,
	galleryImages: null,
	currentImageNo: 0,
	
	initialize: function (galleryPhotos)
	{
		this.galleryPhotos = galleryPhotos + '_photos';
		this.maxImageWidth = Element.getDimensions(this.galleryPhotos).width;
		this.galleryImages = $A($(this.galleryPhotos).getElementsByTagName('img'));
	},

	previousImage: function()
	{
		if (this.moving)
		{
			return false;
		}
		this.moving = true;
		
		var currentImage = this.galleryImages[this.currentImageNo];
		
		var nextImage = null;
		if (this.currentImageNo > 0)
		{
			nextImage = this.galleryImages[this.currentImageNo - 1];
			this.currentImageNo = this.currentImageNo - 1;
		}
		else
		{
			nextImage = this.galleryImages[this.galleryImages.length - 1];
			this.currentImageNo = this.galleryImages.length - 1;
		}
		var movement = this.maxImageWidth;
		
		$(nextImage).setStyle( {left: (-this.maxImageWidth) +'px'} );

		this.runEffects(currentImage, nextImage, movement);
		
		return false;
	},
	
	nextImage: function()
	{
		if (this.moving)
		{
			return false;
		}
		this.moving = true;
		
		var currentImage = this.galleryImages[this.currentImageNo];
		
		var nextImage = null;
		if (this.currentImageNo + 1 < this.galleryImages.length)
		{
			nextImage = this.galleryImages[this.currentImageNo + 1];
			this.currentImageNo = this.currentImageNo + 1;
		}
		else
		{
			nextImage = this.galleryImages[0];
			this.currentImageNo = 0;
		}
		
		var movement = -this.maxImageWidth;
		
		$(nextImage).setStyle( {left: this.maxImageWidth +'px'} );
		
		this.runEffects(currentImage, nextImage, movement);
		
		return false;
	},
	
	runEffects: function(currentImage, nextImage, movement)
	{
		new Effect.Parallel
		(
			[
				new Effect.Opacity(currentImage, { from: 1.0, to: 0, duration: 0.5, delay: 0.2 }),
				new Effect.Move(currentImage, {x: movement, y: 0, duration: 1.0, mode: 'absolute'}),
				new Effect.Opacity(nextImage, { from: 0, to: 1.0, duration: 0.5, delay: 0.2 }),
				new Effect.Move(nextImage, {x: 0, y: 0, duration: 1.0, mode: 'absolute'})
			],
			{ afterFinish: this.movingFin.bind(this, null) }
		);
	},
	
	movingFin: function(e)
	{
		this.moving = false;
	}

}