
/***********************************************
* Fade-in image slideshow script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

/* Modified by joshua vial 12/04/2006 to handle mutliple fades on one page */

var ie4=document.all
var dom=document.getElementById

function ImageFader(uniqueID)
{
	if (uniqueID == null) return false;
	this.uniqueID = uniqueID; //unique id, must be set before fadeImages is called
	this.handle = null; //name of instance variable of object - used for setTimeouts

	this.slideshow_width='60px' //SET IMAGE WIDTH
	this.slideshow_height='371px' //SET IMAGE HEIGHT
	this.pause=9000 //SET PAUSE BETWEEN SLIDE (3000=3 seconds)

	this.fadeimages=new Array()
	//SET 1) IMAGE PATHS, 2) optional link, 3), optional link target:
	//fadeimages[0] = ['../images/fade12.jpg',"",""]

	this.fadeImages = function()
	{
		if (this.uniqueID == null) return false;
		if (this.handle == null) return false;
		//set internal vars
		this.cookieName = this.uniqueID + 'imgNumber';	
		this.canvas0 = this.uniqueID + 'canvas0';
		this.canvas1 = this.uniqueID + 'canvas1';

		this.curpos=10
		this.degree=10
		this.curcanvas= this.canvas0
		this.curimageindex = 0
		this.nextimageindex = 1

		var p = this.fadeimages.length
		if (getCookie(this.cookieName) != null) {
			this.curimageindex = getCookie(this.cookieName);
			this.curimageindex++;
			if (this.curimageindex > (p-1)) this.curimageindex=0;
			setCookie(this.cookieName,this.curimageindex);
		}
		this.nextimageindex = this.curimageindex + 1;
		if (this.nextimageindex > (p-1)) this.nextimageindex=0;

		if (ie4||dom)
		document.write('<div style="z-index:0;position:relative;width:'+this.slideshow_width+';height:'+this.slideshow_height+';overflow:hidden"><div  id="'+this.canvas0+'" 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.canvas1+'" style="position:absolute;width:'+this.slideshow_width+';height:'+this.slideshow_height+';top:0;left:0;filter:alpha(opacity=10);-moz-opacity:10;visibility: hidden"></div></div>')
		else
		document.write('<img name="defaultslide" src="'+ this.fadeimages[j][0]+'">')
	}

	this.insertimage = function(i){
		var tempcontainer=this.fadeimages[i][1]!=""? '<a href="'+this.fadeimages[i][1]+'" target="'+this.fadeimages[i][2]+'">' : ""
		tempcontainer+='<img src="'+this.fadeimages[i][0]+'" border="0">'
		tempcontainer=this.fadeimages[i][1]!=""? tempcontainer+'</a>' : tempcontainer
		return tempcontainer
	}

	this.resetit = function(what){
		this.curpos=10
		var crossobj=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/101;
	}

	this.startit = function(){
		var crossobj=ie4? eval("document.all."+this.curcanvas) : document.getElementById(this.curcanvas)
		crossobj.innerHTML=this.insertimage(this.curimageindex)
		rotateimage(this);

		var preloadedimages=new Array()
		for (p=0;p<this.fadeimages.length;p++){
			preloadedimages[p]=new Image()
			preloadedimages[p].src=this.fadeimages[p][0]
		}
	}
}


	function fadepic(fader){
		if (fader.curpos<100){
			fader.curpos+=10
			if (fader.tempobj.filters)
			fader.tempobj.filters.alpha.opacity=fader.curpos
			else if (fader.tempobj.style.MozOpacity)
			fader.tempobj.style.MozOpacity=fader.curpos/101
		}
		else
		{
			clearInterval(fader.dropslide)
			nextcanvas=(fader.curcanvas==fader.canvas0)? fader.canvas0 : fader.canvas1
			fader.tempobj=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
			fader.tempobj.innerHTML=  fader.insertimage(fader.nextimageindex)
			fader.nextimageindex=(fader.nextimageindex<fader.fadeimages.length-1)? fader.nextimageindex+1 : 0
			var tempobj2=ie4? eval("document.all."+nextcanvas) : document.getElementById(nextcanvas)
			tempobj2.style.visibility="hidden"
			setTimeout('rotateimage(' + fader.handle +')',fader.pause)
		}
	}

	function rotateimage(fader){
		if (ie4||dom){
			fader.resetit(fader.curcanvas)
			var crossobj=fader.tempobj=ie4? eval("document.all."+fader.curcanvas) : document.getElementById(fader.curcanvas)
			crossobj.style.zIndex++
			fader.tempobj.style.visibility="visible"
			fader.dropslide = setInterval('fadepic(' + fader.handle + ')',130);;
			fader.curcanvas=(fader.curcanvas== fader.canvas0)? fader.canvas1 : fader.canvas0;
		}
		else
			document.images.defaultslide.src= fader.fadeimages[fader.curimageindex][0]

		fader.curimageindex=(fader.curimageindex<fader.fadeimages.length-1)? fader.curimageindex+1 : 0
		setCookie(fader.cookieName,fader.curimageindex);
	}
