//requires prototype.js and script.aculo.us
function FadeImage(img_src,elem_id) {
	this.img_elem = new Image();
	this.img_elem.src = img_src;
	this.elem_id = elem_id
}
FadeImage.prototype.preloaded = function() {
	return this.img_elem.complete;
}
FadeImage.prototype.elemId = function() {
	return this.elem_id;
}

var fade_list;
function fadeLoadCheck() {
	fade_list.loadCheck();
}
function startAgain() {
	fade_list.startFades();
}
function FadeList(root_id,fade_class,fade_time,wait_time,interval) {
	this.root_id = root_id;
	this.fade_class = fade_class;
	this.fade_time = fade_time;
	this.wait_time = wait_time;
	this.interval = interval;
	this.sched = false;
	this.list = new Array();
	this.current_index = 0;
	this.next_index = 0;
}
FadeList.prototype.getFadeRunning = function() {
	return this.fade_running;
}
FadeList.prototype.getInterval = function() {
	return this.interval;
}
FadeList.prototype.allLoaded = function() {
	for(var i = 0; i < this.list.length; i++) {
		if(!this.list[i].preloaded())
			return false;
	}
	return true;
}
FadeList.prototype.nextIndex = function() {
	var temp = this.next_index;
	//alert('current: ' + this.current_index + ' next: ' + this.next_index);
	if(this.next_index == this.list.length - 1)
		this.next_index = 0;
	else
		this.next_index = this.next_index + 1;
	this.current_index = temp;
	//alert('current: ' + this.current_index + ' next: ' + this.next_index);
}
FadeList.prototype.startFades = function() {
	this.nextIndex();
	var fade_out_id = this.list[this.current_index].elemId();
	var fade_in_id = this.list[this.next_index].elemId();
	var fade_time_secs = this.fade_time / 1000;
	//alert('out: ' + fade_out_id + ' in: ' + fade_in_id);
	/*new Effect.Opacity(fade_out_id,{duration: fade_time_secs, from: 1.0, to: 0.0});
	new Effect.Opacity(fade_in_id,{duration: fade_time_secs, from: 0.0, to: 1.0});*/
	new Effect.Parallel(
		[
			new Effect.Opacity(fade_out_id,{sync: true, from: 1.0, to: 0.0000001}),
			new Effect.Opacity(fade_in_id,{sync: true, from: 0.0000001, to: 1.0})
		],
		{duration: fade_time_secs});
	this.sched = setTimeout('startAgain()',this.fade_time + this.wait_time);
}
FadeList.prototype.loadCheck = function() {
	if(this.allLoaded())
		this.sched = setTimeout('startAgain()',this.wait_time);
	else
		this.sched = setTimeout('fadeLoadCheck()',200);
}
FadeList.prototype.start = function() {
	var img_elems = $(this.root_id).getElementsByClassName(this.fade_class);
	for(var i = 0; i < img_elems.length; i++)
		this.list[i] = new FadeImage(img_elems[i].src,img_elems[i].id);
	this.sched = setTimeout('fadeLoadCheck()',200);
}