function ImageFaderImage(src,w,h,title,alt) 
{
	this.src = src;
	this.w = w;
	this.h = h;
	this.title = title;
	this.alt = alt;

	this.image = new Image();
	this.image.src = this.src;
}


function ImageFader(instance,img,autostart,delay) 
{
	this.instance = instance;
	this.img = img;
	this.images = new Array();
	this.current = -1;
	this.delay = delay ? delay : 8000;

	if (autostart) this.Start();
}

ImageFader.prototype.GetNumOfImages = function ()
{
	return this.images.length;
}

ImageFader.prototype.AddImage = function (src,w,h,title,alt) 
{
	var x = this.GetNumOfImages();
	var temp_img = new ImageFaderImage(src,w,h,title,alt);
	this.images[x] = temp_img;
	if (this.current < 0) this.current = 0;
}

ImageFader.prototype.Rotate = function () 
{
	var n = this.GetNumOfImages();

	if (n <= 1) 
	{
		this.Start(Math.min(1000,this.delay));
		return;
	}

	// get new current
		var x = this.current;

		do
		{
			x = parseInt(Math.random() * n);
		}
		while (x == this.current);

	// rotate image...
		var img = document.getElementById(this.img); 
		
		if (img)
		{
			var the_filter = null;

			if (img.filters != null)
			{
				if (img.filters.length > 0)	// (ie mac check)
				{	
					if (img.filters[0]) the_filter = img.filters[0];
				}
			}

			if (the_filter) the_filter.apply();

			img.src = this.images[x].image.src;

			if (the_filter) the_filter.play();

				img.style.width = this.images[x].w + "px";
				img.style.height = this.images[x].h + "px";

			// set alt
				img.alt = this.images[x].alt;

			// set title
				img.title = this.images[x].title;

			
			this.current = x;
		}


	this.Start();	
}

ImageFader.prototype.Start = function(delay) 
{
	if (!delay) delay = this.delay;

	setTimeout(this.instance + ".Rotate()",delay);
}