
/////////////////////////////////////////////////////////////////////////////////
function Fade(id_fade, fadeImages,  width, height) {
	
	this.id = id_fade;
	this.fadeimages = fadeImages;
	
	this.curcanvas = id_fade + "0";
	this.curimageindex=0;

	this.slideshow_width = width; 
	this.slideshow_height = height; 
	this.pause=3000; //pause between slides (3000 = 3 seconds)

	this.ie4=document.all;
	this.ie55=window.createPopup;
	this.dom=document.getElementById;

	this.curpos=10;
	this.degree=10;

	this.nextimageindex=1;

	this.c0= id_fade + "0";
	this.c1= id_fade + "1";
	
	this.imageholder = new Array();
	
	this.tempobj = 0;
	this.dropslide = 0;
	
	this.whichlink=0;
	this.whichimage=0;


	if (this.ie55) {
		this.init_ie();
	} else {
		this.init();
	}	
}

/////////////////////////////////////////////////////////////////////////////////
Fade.prototype.fadepic = function () {
	if (this.curpos < 100) {
		this.curpos += 10;
		if (this.tempobj.filters) {
			this.tempobj.filters.alpha.opacity = this.curpos;
		}	
		else if (this.tempobj.style.MozOpacity) {
				this.tempobj.style.MozOpacity=this.curpos/100;
			 }
	} else {
		clearInterval(this.dropslide);
		var nextcanvas=(this.curcanvas==this.c0)? this.c0 : this.c1;
		this.tempobj= this.ie4? eval("document.all." + nextcanvas) : document.getElementById(nextcanvas);
		this.tempobj.innerHTML='<img  src="'+this.fadeimages[this.nextimageindex]+'">';
		this.nextimageindex = (this.nextimageindex<this.fadeimages.length-1)? this.nextimageindex+1 : 0
		setTimeout(this.id + ".rotateimage()", this.pause);
	}
}

////////////////////////////////////////////////////////////////////////////////
Fade.prototype.rotateimage = function () {
	if (this.ie4 || this.dom) {
		this.resetit(this.curcanvas);
		this.tempobj = this.ie4? eval("document.all."+this.curcanvas) : document.getElementById(this.curcanvas);
		var crossobj = this.tempobj;
		crossobj.style.zIndex++;
		var temp='setInterval("' + this.id + '.fadepic()",50)';
		this.dropslide = eval(temp);
		this.curcanvas=(this.curcanvas==(this.id + "0"))? this.id + "1" : this.id + "0";
	} else {
		var defaultslide = eval("document.images." + this.id + "defaultslide");
		if (defaultslide) {
			defaultslide.src = this.fadeimages[this.curimageindex];
		}	
	}	
	this.curimageindex=(this.curimageindex<this.fadeimages.length-1)? this.curimageindex+1 : 0;
}

////////////////////////////////////////////////////////////////////////////////
Fade.prototype.resetit = function (what) {

	this.curpos=10;
	var crossobj=this.ie4? eval("document.all."+what) : document.getElementById(what);
	if (crossobj.filters) {
		crossobj.filters.alpha.opacity=this.curpos;
	} else if (crossobj.style.MozOpacity) {
		crossobj.style.MozOpacity=this.curpos/100;
	}
}

///////////////////////////////////////////////////////////
Fade.prototype.startit = function () {
	var crossobj=this.ie4 ? eval("document.all."+this.curcanvas) : document.getElementById(this.curcanvas);
	crossobj.innerHTML='<img src="'+fadeimages[this.curimageindex]+'">';
	this.rotateimage();
}

//////////////////////////////////////////////////////////
Fade.prototype.init = function () {
	
	////NO need to edit beyond here/////////////			
	var preloadedimages = new Array();
	
	for (p=0; p<this.fadeimages.length; p++) {
		preloadedimages[p]=new Image();
		preloadedimages[p].src=this.fadeimages[p];
	}
	
	
	if (this.ie4 || this.dom) {
		document.write('<div style="position:relative;width:'+this.slideshow_width+';height:'+this.slideshow_height+';overflow:hidden"><div  id="'+this.id+'0" style="position:absolute;width:'+this.slideshow_width+';height:'+this.slideshow_height+';top:0;left:0;filter:alpha(opacity=10);-moz-opacity:10"></div><div id="'+this.id+'1" style="position:absolute;width:'+this.slideshow_width+';height:'+this.slideshow_height+';top:0;left:0;filter:alpha(opacity=10);-moz-opacity:10"></div></div>');
	} else {
		document.write('<img  name="'+this.id+'defaultslide" src="'+this.fadeimages[0]+'">');
	}	
	if (this.ie4 || this.dom) {
		this.startit();
	} else {
		setInterval(this.id + ".rotateimage()", this.pause);
	}	
}

//////////////////////////////////////////////////////////
Fade.prototype.init_ie = function () {
	
	for (i=0; i<this.fadeimages.length; i++)
	{
		this.imageholder[i]=new Image();
		this.imageholder[i].src=this.fadeimages[i];
	}
	if (this.ie55) {
		document.write('<img src="" id="'+this.id+'ie" width="'+this.slideshow_width+'" height="'+this.slideshow_height+'" border="0" style="filter:progid:DXImageTransform.Microsoft.Pixelate(MaxSquare=10,Duration=1)">');
	}
	this.slideit();
}

//////////////////////////////////////////////////////////
Fade.prototype.slideit = function () {
	if (!document.images) return;
	var slide = document.getElementById(this.id+'ie');
	if (this.ie55 && slide) {
		slide.style.filter=getImageStyleFilter();
		slide.filters[0].apply();
		slide.src = this.imageholder[this.whichimage].src;
		slide.filters[0].play();
		this.whichlink = this.whichimage;
		this.whichimage = (this.whichimage < this.fadeimages.length-1)? this.whichimage+1 : 0
		setTimeout(this.id + ".slideit()", this.pause );
	}	
}

function getImageStyleFilter() {
	var r = Math.round(9*Math.random());
	switch(r) {
		case 1:
			return 'progid:DXImageTransform.Microsoft.Wheel(duration=1, spokes=8)';
		case 2:
			return 'progid:DXImageTransform.Microsoft.Spiral(duration=1, GridSizeX=25, GridSizeY=25)';
		case 3:
			return 'progid:DXImageTransform.Microsoft.Zigzag(duration=1, GridSizeX=25, GridSizeY=25)';
		case 4:
			return 'progid:DXImageTransform.Microsoft.Strips(duration=1, motion="rightdown")';
		case 5:	
			return 'progid:DXImageTransform.Microsoft.RandomDissolve(duration=1)';
		case 6:	
			return 'progid:DXImageTransform.Microsoft.RandomBars(duration=1)';
		case 7:	
			return 'progid:DXImageTransform.Microsoft.Iris(duration=1)';
		case 8:		
			return 'progid:DXImageTransform.Microsoft.gradientWipe(duration=1, gradientsize=0.5)';
		case 9:	
			return 'progid:DXImageTransform.Microsoft.Fade(duration=1)';
		default:
		 	return 'progid:DXImageTransform.Microsoft.Pixelate(MaxSquare=10,Duration=1)';
	}
}
				





				

