var picCount = 0;
var picArr;
var currentPic = 0;
var imagesDir = 'images/slides/';		// can be changed based on the images directory
var fadeoutTime = 10;			// can be changed for the fadeout timing (in seconds)
var fadeinTime = 2000;			// can be changed for the fadein timing (in seconds)
var imgdisplayTime = 3000		// how long the image to be displayed
var imgElementId = 'idSlide';

function getPicturesList(){

	$.ajax({
		url 		: 'images/slides/imageRotator.php',
		type 		: 'POST',
		dataType 	: 'json',
		data 		: 'call=imgslist',
		success 	: function(retval){
						picArr = retval;
						picCount = picArr.length;	
						if(picCount > 0){
							rotatePicture();
						}else{
							alert('No images found');
						}
					}
	});
}

function rotatePicture(){
	if(currentPic >= picCount){
		currentPic = 0;
	}	
	$('#' + imgElementId).fadeOut(fadeoutTime);
	setTimeout('changePicture()', fadeoutTime);	
}

function changePicture(){
	$('#' + imgElementId).attr('src', imagesDir + picArr[currentPic]);
	$('#' + imgElementId).attr('alt', picArr[currentPic] + ' missing');
	$('#' + imgElementId).fadeIn(fadeinTime);
	if(currentPic < picCount){
		currentPic++;
	}
	setTimeout('rotatePicture()', imgdisplayTime);	
}
