$ = function (id) { return document.getElementById(id); }

function setOpacity(op, id) {
	var obj = $(id);
	if (obj) {
		obj.style.filter = "alpha(opacity="+op+")";				// IE
		obj.style.opacity = (op/100);						// CSS-3
		obj.style.KhtmlOpacity = (op/100);					// Safari, Konqueror
	}
} 

apsClass = function(name, fadeTime, holdTime)
{
	this.interval = 50;							// interval in ms
	this.nAps;
	this.name = name;							// my name
	this.item = 0;
	this.lastItem = 0;
	this.holdTime = holdTime;						// total time to hold image from start of fade
	this.fadeTime = fadeTime;						// how much time to take to do fade
	
	var i;
	var obj;

	for (this.nAps = 0; ; this.nAps++) {
		obj = $('ap'+this.nAps);
		if (obj) {
			setOpacity(0, "ap"+this.nAps);
			obj.style.visibility = 'visible';
		} else {
			break;
		}
	}

	this.fade = function (id, start, end, duration) {
		var opacityInc;
		var i;
		var opacity;
		
		parts = Math.floor(duration / this.interval);			// how many slices per durations
		opacityInc = (end - start) / parts;
		
		for (i = 0, opacity = start, t=0; i < parts; i++) {
			t += this.interval;
			opacity += opacityInc;
			setTimeout("setOpacity(" + opacity + ",'" + id +"')", t);
		}
		setTimeout("setOpacity(" + end + ",'" + id +"')", t);
	}

	this.doit = function()
	{
		this.fade('ap0',0,99,this.fadeTime);				// Fade-in 1st image
		this.item++;
		setTimeout(this.name+".doitLoop()", this.holdTime);		// call forever loop
	}

	this.doitLoop = function()
	{
		this.fade('ap'+this.item,0,99,this.fadeTime);			// Fade-in next item
		this.fade('ap'+this.lastItem,99,0,this.fadeTime);		// Fade-out next item

		this.lastItem = this.item;
		this.item++;						
		if (this.item >= this.nAps) {					// don't use mod (%) -- requires more cycles
			this.item = 0;						// back to the first image
		}

		setTimeout(this.name+'.doitLoop()', this.holdTime);		// Do 'er again
	}
}

var aps;

initAps = function()
{
	aps = new apsClass("aps", 500, 7000); //500 = time to fade = 1/2 msec; 2500 = time in msec image appears
	aps.doit();
}


