function SlideShow(container, width, height, options)
{
	if(!document.getElementById || !document.createElement)return;
	
	if (!options){options={};}
	this.delay = (options.delay || 4800);
	this.frameDelay = (options.frameDelay || 50);
	this.step = (options.step || 5);
	this.repeatFirstImage = (options.repeatFirstImage || true);
	if (options.repeatFirstImage == "no")
	{
		this.repeatFirstImage = false;
	}
	this.current = 0;
	this.imgs = new Array();
	this.step = this.step/100;
	this.timer = null;
	
	document.getElementById(container).style.position = 'relative';
	document.getElementById(container).style.width = width+'px';
	document.getElementById(container).style.height = height+'px';

	this.imgs = document.getElementById(container).getElementsByTagName("img");
	for(i=0;i<this.imgs.length;i++) {
		if (i!=0) {this.imgs[i].xOpacity = 0;}
		this.imgs[i].style.position = 'absolute';
		this.imgs[i].style.top = 0;
		this.imgs[i].style.left = 0;
	}
	this.imgs[0].style.display = "block";
	this.imgs[0].xOpacity = .99;
	var self = this;
	this.playing = true;
	this.timer = setTimeout(function(){self.xfade()},this.delay);
}

SlideShow.prototype =
{
	prev: function () {
		this.stop();
		var self = this;
		this.reverse = true;
		setTimeout(function(){self.xfade()},this.frameDelay);
	},

	next: function () {
		this.stop();
		var self = this;
		setTimeout(function(){self.xfade()},this.frameDelay);
	},

	play: function () {
		if (this.timer == null)
		{
			this.playing = true;
			var self = this;
			this.timer = setTimeout(function(){self.xfade()},this.frameDelay);
		}
	},

	stop: function () {
		if (this.timer != null)
		{
			clearTimeout(this.timer);
			this.timer = null;
		}
		this.playing = false;
	},
	
	xfade: function ()
	{
		cOpacity = this.imgs[this.current].xOpacity;
		if (this.reverse == true)
		{
			nIndex = (this.current > 0) ? this.current-1 : this.imgs.length-1;
		}
		else
		{
			nIndex = this.imgs[this.current+1] ? this.current+1 : 0;
		}
		if (this.repeatFirstImage == false)
		{	
			if (nIndex == 0)
			{
				nIndex = 1;
			}
		}
		nOpacity = this.imgs[nIndex].xOpacity;
		
		cOpacity-=this.step; 
		nOpacity+=this.step;
		
		this.imgs[nIndex].style.display = "block";
		this.imgs[this.current].xOpacity = cOpacity;
		this.imgs[nIndex].xOpacity = nOpacity;
		
		this.setOpacity(this.imgs[this.current]); 
		this.setOpacity(this.imgs[nIndex]);
		var self = this;
		if(cOpacity<=0)
		{
			this.imgs[this.current].style.display = "none";
			this.current = nIndex;
			
			if (this.playing == true)
			{
				this.reverse = false;
				this.timer = setTimeout(function(){self.xfade()},this.delay);
			}
		}
		else
		{	
			setTimeout(function(){self.xfade()},this.frameDelay);	
		}
	},

	setOpacity: function (obj)
	{
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
}
