var picAmount = 0;
var imageSrc_array;
var picNumber = 1;
var timerID;
var i = 0;
var j = 0;
var playing = false;

function pauseRotation () {
  clearTimeout (timerID);
  playing = false;
}

function initializeRotation () {
	imageSrc_array=imageSrc.split(",");
	picAmount = imageSrc_array.length;
}

function playRotation (imageSrc) {
 if (playing == false) {
    doRotation (imageSrc);
 }
}

function doRotation (imageSrc) {
	initializeRotation();
    j = j + 1;
    if (j >= picAmount) j = 0;
    
    document.getElementById(objPropertyImage).src = imageSrc_array[j];
	
    picNumber = picNumber + 1
    if (picNumber > picAmount) picNumber = 1;
    timerID = setTimeout("doRotation('"+picAmount+"','"+imageSrc+"')", 3000);

    playing = true;
  
  }
  
function goToExecute (imageSrc) {
  if (playing == false) {
	initializeRotation();

    j = j + 1;
    if (j >= picAmount) j = 0;
    document.getElementById(objPropertyImage).src = imageSrc_array[j];
    
    picNumber = picNumber + 1
    if (picNumber > picAmount) picNumber = 1;
  }

  if (playing == true) doRotation(picAmount ,imageSrc);
}

function goToNext (imageSrc) {
  clearTimeout (timerID);
  goToExecute(picAmount, imageSrc);
}

function goToPrevious (imageSrc) {
  clearTimeout (timerID);
  initializeRotation();

  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);
}
