﻿function ImageGallery(IDobj, slideTime)
{
	this.obj = Get(IDobj);
	this.slideTime = (slideTime)? slideTime : 6000;
	this.images = new Array();
	this.currentImage = null;
	//
	this.guid = 'ImageGallery_' + IDobj;
	eval('window.' + this.guid + '=this');
};

ImageGallery.prototype.AddImage = function(imageUrl)
{
	this.images.push(imageUrl);
};

ImageGallery.prototype.Initialize = function()
{
	//
	if (this.images.length != 0)
		this.LoadImage(0);
};

ImageGallery.prototype.LoadImage = function(index)
{
	//
	if (index >= this.images.length)
		index = 0;
	//
	var container = Create('DIV', this.obj);
	container.style.opacity = '0.0';
	container.style.filter = 'alpha(opacity=100)';
	//container.style.height = '0px';
	container.style.position = 'absolute';
	container.style.overflow = 'visible';
	//
	var image = Create('IMG', container);
	image.ImageGallery = this;
	image.index = index;
	image.onload = image.onerror = function()
	{
		this.ImageGallery.currentImage = this.index;
		Fade.To(image.parentNode, 1);
		//
		window.setTimeout('window.' + this.ImageGallery.guid + '.LoadImage(' + (this.index + 1) + ')', this.ImageGallery.slideTime);

		// make previous images fade out and then remove them
		for (var i = 0; i < this.ImageGallery.obj.childNodes.length; i++)
		{
			var currentImage = this.ImageGallery.obj.childNodes[i];
			if (currentImage != container)
			{
				if (currentImage.style.opacity == '0')
					currentImage.parentNode.removeChild(currentImage);
				else
					Fade.To(currentImage, 0);
			}
		}
	};
	image.src = this.images[index];
};


