var picAmount;
var imageSrc_array;
var imageDesc_array;
var picNumber = 1;
var timerID;
var i = 0;
var j = 0;
var playing = false;

function pauseRotation () {
  clearTimeout (timerID);
  playing = false;
}
function playRotation (picAmount,imageSrc,imageDesc) {
 if (playing == false) {
    doRotation (picAmount,imageSrc,imageDesc);
 }
}
function doRotation (picAmount, imageSrc,imageDesc) {

	imageSrc_array=imageSrc.split(",");
	imageDesc_array=imageDesc.split(",");

    j = j + 1
    if (j >= picAmount) j = 0;
    picProperty.src = imageSrc_array[j];
	document.getElementById('picCaption').innerHTML = imageDesc_array[j];
	
    picNumber = picNumber + 1
    if (picNumber > picAmount) picNumber = 1;
    timerID = setTimeout("doRotation('"+picAmount+"','"+imageSrc+"','"+imageDesc+"')", 3000);

    playing = true;
  
  }
  
function goToExecute (picAmount, imageSrc,imageDesc) {
  if (playing == false) {
    imageSrc_array=imageSrc.split(",");
	imageDesc_array=imageDesc.split(",");

    j = j + 1
    if (j >= picAmount) j = 0;
    picProperty.src = imageSrc_array[j];
    document.getElementById('picCaption').innerHTML = imageDesc_array[j];

    picNumber = picNumber + 1
    if (picNumber > picAmount) picNumber = 1;
  }

  if (playing == true) doRotation(picAmount ,imageSrc,imageDesc);
}

function goToNext (picAmount, imageSrc,imageDesc) {
  clearTimeout (timerID);
  goToExecute(picAmount, imageSrc,imageDesc);
}

function goToPrevious (picAmount, imageSrc,imageDesc) {
  clearTimeout (timerID);
  imageSrc_array=imageSrc.split(",");
  imageDesc_array=imageDesc.split(",");

  j = j - 2

  if (j < -1) j = picAmount - 2;
  if (j == -1) j = picAmount - 1;

  
  picNumber = picNumber - 2
  if (picNumber < 0) picNumber = picAmount - 1;
  if (picNumber == 0) picNumber = picAmount;
  goToExecute(picAmount, imageSrc,imageDesc);
}