Event.observe(window, 'load', image_switch_start);

var flippers = [];

function image_switch_start(){
	var flipper_containers = document.getElementsByClassName('imageflip_container');
	
	for(var i=0 ; i<flipper_containers.length ; i++){
		flippers[i] = new flipper(flipper_containers[i]);
		var t=i*3000;
		setTimeout( 'setInterval ( "flippers[' + i + '].flip()", 8000 );',t)
	}
}

function flipper(dom_obj){
	this.current_image = 0;
	this.images = dom_obj.getElementsByClassName('imageflip_inner');
	if(this.images.length>1){
		this.flip = flip;
	}else{
		this.flip = doNothing;
	}
}

function doNothing(){
	return true;
}

function flip(){

	if(this.current_image+1 >= this.images.length){
		next_image = 0;
	}else{
		next_image = this.current_image+1;
	}
	
//	alert('cur:' + this.current_image + ' next: ' + next_image);
	Effect.Fade(this.images[this.current_image], { duration: 3.0 });
	Effect.Appear(this.images[next_image], { duration: 3.0 });	
	this.current_image = next_image;
}




