// JavaScript Document
function DiaShow() {
	
	var imgarr = new Array();
	var index = 0;
	var _self = this;
	
	this.setImages = function(images) {
		imgarr = images;
	}
	
	this.start = function() {
		dojo.style("show_animation","opacity","0");
		dojo.byId("show_animation").src = getImage();
		fadeIn();
		inter = setInterval ( function() { _self.fadenOut() }, 4000 );	
		
	}
	
	
	this.fadenOut = function() {
		dojo.style("show_animation", "opacity", "1");
		
		if(dojo.isOpera) {
			dojo.style("show_animation", "opacity", "0");
			dojo.byId("show_animation").src = getNextImage();
			fadeIn();
		} else {
			var fadeOutArgs = {
					node: "show_animation",
					duration: 1000,
					onEnd: function() {
						dojo.byId("show_animation").src = getNextImage();
						fadeIn();
					}
					
			};
			dojo.fadeOut(fadeOutArgs).play();
		}
	}
	
	
	var fadeIn = function() {
		if(dojo.isOpera) {
			dojo.style("show_animation", "opacity", "1");
			
			preloadNextImage();
		} else {
			var fadeArgs = {
					node: "show_animation",
					duration: 1000,
					onEnd: function() {
	
						preloadNextImage();
					}
			};
			dojo.fadeIn(fadeArgs).play();
		}
	}
	
	var getImage = function() {
		
		return imgarr[index];
	}
	
	var getNextImage = function() {
		index++;
		
		if(index == imgarr.length) {
			index = 0;
		}
		
		return imgarr[index];
	}
	
	var preloadNextImage = function() {
			var p		= new Image();
			p.onload  	= update;
			p.src	= getNextImage();
			index--;
	}
	
	var update = function() {
		
	}

	
}