function ImageRotate(elementName,fadeDelay,imageDelay) {
	this.d = null;
	this.imgs = new Array()
	this.zInterval = null
	this.current = 0
	this.pause=false;
	this.t1 = null;
	this.t2 = null;
	this.t3 = null;
	
	this.element = elementName;
	
	this.fadeDelay = fadeDelay?fadeDelay:125;
	this.imageDelay = imageDelay?imageDelay:3000;
	
	this.ondisplay = null;
}

ImageRotate.isMSIE = (navigator.appName == "Microsoft Internet Explorer");
ImageRotate.isMSIE5 = ImageRotate.isMSIE && (navigator.userAgent.indexOf('MSIE 5') != -1);
ImageRotate.isMSIE5_0 = ImageRotate.isMSIE && (navigator.userAgent.indexOf('MSIE 5.0') != -1);
ImageRotate.isGecko = navigator.userAgent.indexOf('Gecko') != -1;
ImageRotate.isMAC = navigator.userAgent.indexOf("Mac") > -1;

ImageRotate.prototype.init = function(start) {
	ImageRotate.addEvent(window,"load",start);
}

ImageRotate.prototype.start = function(autostart) {
	var obj = this;
	
	this.d = document;

	if (!this.d.getElementById || !this.d.createElement) return;
	
	if (!this.d.getElementById(this.element)) return;
	
	this.imgs = this.d.getElementById(this.element).getElementsByTagName("img");

	if(this.imgs.length>0){
	    for(var i=1;i < this.imgs.length;i++)  {
			this.imgs[i].xOpacity = 0;
			this.imgs[i].style.opacity = 0;
			this.imgs[i].style.MozOpacity = 0;
			this.imgs[i].style.filter = "alpha(opacity=0)";
			this.imgs[i].style.display = "none";
		}
		this.imgs[0].style.display = "block";
		
		if (autostart)
		    this.t1 = setTimeout(function () {obj.fade(obj);},1000);
		
		if (obj.ondisplay) {
			obj.ondisplay(0);
		}
	}
}

ImageRotate.prototype.play = function() {
	if (this.pause) {
		this.pause = false;
		
		this.fade(this);
	}
	
	return false;
}

ImageRotate.prototype.stop = function() {
	this.pause = true;
	
	return false;
}

ImageRotate.prototype.displayImage = function(index) {
	var obj = this;
	
	obj.pause = true;
	clearTimeout(obj.t1);
	clearTimeout(obj.t2);
	
	for(i=0;i<obj.imgs.length;i++) 
	{
	    obj.imgs[i].xOpacity = 0;
		obj.imgs[i].style.opacity = 0;
		obj.imgs[i].style.MozOpacity = 0;
		obj.imgs[i].style.filter = "alpha(opacity=0)";
	}
	
	obj.current = index;
    obj.imgs[obj.current].style.display = "block";
	obj.imgs[obj.current].xOpacity = 100;
	obj.imgs[obj.current].style.opacity = 100;
	obj.imgs[obj.current].style.MozOpacity = 100;
	obj.imgs[obj.current].style.filter = "alpha(opacity=100)";
	
	if (obj.ondisplay) {
		obj.ondisplay(obj.current);
	}
	
	return false;
}

ImageRotate.prototype.fadeIn = function(obj) {
}

ImageRotate.prototype.fade = function(obj) {
	var cOpacity = obj.imgs[obj.current].xOpacity?obj.imgs[obj.current].xOpacity:.99;
	var nIndex = obj.imgs[obj.current + 1]?obj.current + 1:0;
	var nOpacity = obj.imgs[nIndex].xOpacity;
		
	cOpacity -= .05; 
	nOpacity += .05;
	
	obj.imgs[nIndex].style.display = "block";
	obj.imgs[obj.current].xOpacity = cOpacity;
	obj.imgs[nIndex].xOpacity = nOpacity;
	
	ImageRotate.setOpacity(obj.imgs[obj.current]); 
	ImageRotate.setOpacity(obj.imgs[nIndex]);
	
	if(cOpacity <= 0) {
		obj.imgs[obj.current].style.display = "none";
		obj.current = nIndex;
		
		if (!obj.pause)
			obj.t2 = setTimeout(function () {obj.fade(obj);},obj.imageDelay);
		
		if (obj.ondisplay) {
			obj.ondisplay(nIndex);
		}
	} else {
		obj.t2 = setTimeout(function () {obj.fade(obj);},obj.fadeDelay);
	}
}

ImageRotate.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) + ")";
}

ImageRotate.addEvent = function (obj, name, handler) {
	// Browser check
	if (ImageRotate.isMSIE)
		if (!ImageRotate.isMAC) {
			obj.attachEvent("on" + name, handler);
		} else {
			switch (name) {
				case 'load':obj.onload = handler;break;
				case 'focus':obj.onfocus = handler;break;
				case 'blur':obj.onblur = handler;break;
				case 'resize':obj.onresize = handler;break;
			}
		}
	else
		obj.addEventListener(name, handler, false);
};