if(!SA) var SA = {};

SA.FadingImages = {
	init:function(images,delay){
		this.images = new Array();
		this.images = images;
		this.container = $("splash");
		this.preload();
		this.curIndex = 0;
		this.duration = 0.5;
		this.delayInSeconds = (delay || 2) ;
	},
	
	preload:function(){
		var image = new Array();
		for(i = 0 ; i < this.images.length; i++ ){
			image[i] = new Image();
			image[i].src = this.images[i];
		}
	},
	
	setImages:function(){
		var ul = SA.createElement("ul", {id:'fadeImages'});
		this.container.update(ul);
		for(i=0; i < this.images.length;i++){
			var li = SA.createElement("li",{id:i});
			var image = SA.createImage({src:this.images[i]});
			ul.insert(li.update(image));
			if(i!==0) li.hide();
		}
		this.start();	
	},
	
	start:function() {
		setTimeout("SA.fadeInOut(SA.curIndex)", this.delayInSeconds * 1000);
	},
	
	
	fadeInOut:function(index) {
			Effect.Fade(index.toString());
			(index == (this.images.length-1) ) ?index = this.curIndex:index++ ;
			var id = index.toString();
			setTimeout(function(){Effect.Appear(id);}, 0);
			setTimeout(function(){SA.fadeInOut(id);}, (this.delayInSeconds * 1000) + 1850 );
	}
}

Object.extend(SA,SA.FadingImages);

