var fadePerStep					= 1; // How many percent to fade per step?
var fadingTime					= 300; // Miliseconds (seconds * 1000)
var stayTime					= 4000; // Miliseconds (seconds * 1000)
var imageNo						= new Array();
var fading						= new Array();
var newPictureStatus			= new Array();
var w							= new Array();
var n							= new Array();
var currentOpacity				= new Array();
var newOpacity					= new Array();
var currentPage					= 'images/examples/overons/';
imageNo['topcenterIMG']				= 0;
imageNo['bottomleftIMG']			= 0;
imageNo['mainIMG']					= 0;
newPictureStatus['topcenterIMG']	= 1;
newPictureStatus['bottomleftIMG']	= 1;
newPictureStatus['mainIMG']			= 1;

function fadeIn(which) {
	w[which]						= document.getElementById(which);
	currentOpacity[which]			= Math.round(w[which].style.opacity*100);
	newOpacity[which]				= Math.round(currentOpacity[which]+fadePerStep);
	
	clearInterval(fading[which]);
	
	if(currentOpacity[which] >= 100) {
		if(imagesArray[which].length > 1 || w[which].src != imagesArray[which][0]) {
			fading[which]					= setTimeout("fadeOut('"+which+"');", Math.round(4000+Math.random()*(stayTime-1000)));
		}
		return;
	}
	
	if(currentOpacity[which] < 0)
		currentOpacity[which]			= 0;
	
	w[which].style.opacity			= ( newOpacity[which] / 100 );
	w[which].style.MozOpacity		= ( newOpacity[which] / 100 );
	w[which].style.KhtmlOpacity		= ( newOpacity[which] / 100 );
	w[which].style.filter			= "alpha(opacity=" + newOpacity[which] + ")"; 
	fading[which]					= setTimeout("fadeIn('"+which+"');", Math.round(fadingTime / 100 * fadePerStep));
}

function fadeOut(which) {
	w[which]						= document.getElementById(which);
	currentOpacity[which]			= Math.round(w[which].style.opacity*100);
	newOpacity[which]				= Math.round(currentOpacity[which]-fadePerStep);
	
	if(imagesArray[which].length > 1 || w[which].src != imagesArray[which][0]) {
		clearInterval(fading[which]);
		
		if(currentOpacity[which] > 100)
			currentOpacity[which]			= 100;
		
		if(currentOpacity[which] <= 0) {
			replaceImage(which);
			return;
		}
		
		w[which].style.opacity			= ( newOpacity[which] / 100 );
		w[which].style.MozOpacity		= ( newOpacity[which] / 100 );
		w[which].style.KhtmlOpacity		= ( newOpacity[which] / 100 );
		w[which].style.filter			= "alpha(opacity=" + newOpacity[which] + ")"; 
		fading[which]					= setTimeout("fadeOut('"+which+"');", Math.round(fadingTime / 100 * fadePerStep));
	}
}

function replaceImage(which) {
	w[which]						= document.getElementById( which );
	n[which]						= document.getElementById( which + 'New' );
	if(newPictureStatus[which] == 1) {
		if(imageNo[which] >= imagesArray[which].length)
			imageNo[which]					= 0;
		w[which].src					= imagesArray[which][imageNo[which]];
		
		fadeIn(which);
		
		imageNo[which]++;
		if(imageNo[which] >= imagesArray[which].length)
			imageNo[which]					= 0;
		n[which].src					= imagesArray[which][imageNo[which]];
	} else {
		setTimeout("replaceImage('"+which+"');", 300);
	}
	return true;
}

function newPicLoaded(which) {
	newPictureStatus[which]		= 1;
	return true;
}
/*
function notify() {
	alert(document.getElementById('mainIMG').src);
}

setInterval("notify();", 2000);*/
