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.alignRight = (options.alignRight || false);
	this.repeatFirstImage = (options.repeatFirstImage || true);
	this.current = 0;
	this.imgs = new Array();
	this.step = this.step/100;
	
	document.getElementById(container).style.position = 'relative';
	document.getElementById(container).style.width = width+'px';
	document.getElementById(container).style.height = height+'px';

	this.imgs = getElementsByClassName(document.getElementById(container),"div","pngimg");
	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;
		if (this.alignRight) { this.imgs[i].style.right = 0; }
		else {this.imgs[i].style.left = 0; }
	}
	this.imgs[0].style.display = "block";
	this.imgs[0].xOpacity = .99;
	var self = this;
	setTimeout(function(){self.xfade()},this.delay);
}

SlideShow.prototype =
{
	xfade: function ()
	{
		cOpacity = this.imgs[this.current].xOpacity;
		nIndex = this.imgs[this.current+1]?this.current+1:0;
		if (!this.repeatFirstImage && 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;
			
			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) + ")";
	}
}

function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}
