function photofader(nm, mainDiv, imgArr, speed, delay){
	this.name	= nm;
	this.imgArr = imgArr;
	this.curImg = 0;
	this.curDiv = 1;
	this.mainDiv = mainDiv;
	this.speed = speed;
	this.delay = delay;
	
	var mainDv = document.getElementById(mainDiv);
	
	// Store the object so it can be retrieved by the timer.
	eval('document.pfObj_' + mainDiv + ' = this');
	
	document.write("<style type='text/css'>\n");
	document.write("#pf_photo1_" + mainDiv + " img { visibility:hidden; }\n");
	document.write("#pf_photo1_" + mainDiv + " { position:absolute; z-index: 1; }\n");
	document.write("#pf_photo2_" + mainDiv + " { position:absolute; z-index: 0; }\n");
	document.write("</style>");
	
	this.initImages = function() {
		var hldr1 = "pf_photo1_" + mainDiv;
		var hldr2 = "pf_photo2_" + mainDiv;
		
		var dv1 = document.createElement("div");
				dv1.id = hldr1;
				dv1.innerHTML = "<img src='"+ imgArr[0] +"' />";
		var dv2 = document.createElement("div");
				dv2.id = hldr2;
		
		mainDv.appendChild(dv1);
		mainDv.appendChild(dv2);
		
	  image1 = document.getElementById(hldr1).childNodes[0];
		
	  setOpacity(image1, 0);
	  image1.style.visibility = 'visible';
	  this.fadeIn(hldr1,0);
	}
	
	this.fadeIn = function (objId,opacity) {
		if (document.getElementById) {
			obj = document.getElementById(objId).childNodes[0];
			if (opacity < 100) {
				this.speed = (this.speed < 2) ? 2 : this.speed;
				setOpacity(obj, opacity);
				opacityDif = Math.ceil((100-opacity)/speed);
				opacity += opacityDif;
				//opacity += 2;
				window.setTimeout("document.pfObj_" + this.mainDiv + ".fadeIn('"+objId+"',"+opacity+")", 100);
			}
			else
				setTimeout("document.pfObj_" + this.mainDiv + ".swapImages()",this.delay*1000);
		}
	}
	
	this.swapImages = function() {
		// find out which 
		if(this.curImg == this.imgArr.length-1)
			this.curImg = 0;
		else 
			++this.curImg;
	
		// now get the div to hld the new image
		var dvName = (this.curDiv == 1) ? "pf_photo2_" + this.mainDiv : "pf_photo1_" + this.mainDiv;
		var eDivName = (this.curDiv == 1) ? "pf_photo1_" + this.mainDiv : "pf_photo2_" + this.mainDiv;
		this.curDiv = (this.curDiv == 1) ? 2 : 1;
		
		var tgtDiv = document.getElementById(dvName);
		var eDiv = document.getElementById(eDivName);
		
		// now fill the target div
		tgtDiv.innerHTML = "<img src='"+ this.imgArr[this.curImg] +"' style='visibility:hidden;' />";
		
		//move the divs around in z-index
		eDiv.style.zIndex = 0;
		tgtDiv.style.zIndex = 1;
		
		// And finally fade in the image
		
		var img = tgtDiv.childNodes[0];
		
		setOpacity(img, 0);
		img.style.visibility = 'visible';
		this.fadeIn(tgtDiv.id,0);
	}
	
	this.initImages();
}
	
function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  
  // IE/Win
  obj.style.filter = "alpha(opacity:"+opacity+")";
  
  // Safari<1.2, Konqueror
  obj.style.KHTMLOpacity = opacity/100;
  
  // Older Mozilla and Firefox
  obj.style.MozOpacity = opacity/100;
  
  // Safari 1.2, newer Firefox and Mozilla, CSS3
  obj.style.opacity = opacity/100;
}


