/**
 * fade out of an single image
 *
 */
changeImage = function(){
	$(idsToChange[i].id).fade({
		duration: secondsToChange,
		from: 1,
		to: 0,
		afterFinish: setStylesAndChangeNextImage
	});
}

/**
 * set styles of an single image
 * set command to change next image
 *
 */
setStylesAndChangeNextImage = function(){
	correctZIndex();
	$(idsToChange[i].id).show();

	i = getNextI(i);

	// Set command to change next image
	window.setTimeout("changeImage()", (secondsToChange*1000));
}

correctZIndex = function(){
	var k = 0;
	var m = getNextI(i+1);

	// Set next image
	$(idsToChange[getNextI(i)].id).setStyle({
		zIndex: (10*idsToChange.length)
	});

	while(k < idsToChange.length){

		if(m != getNextI(i)){
			$(idsToChange[m].id).setStyle({
				zIndex: (10*idsToChange.length)-(10*(k+1))
			});
		}
		m = getNextI(m);
		k++;
	}
}

getNextI = function(imageNum){
	var j = imageNum+1;

	if(j > (idsToChange.length-1)){
		j = 0;
	}

	return j;
}
