var picAmount;
var imageSrc_array;
var imageDesc_array;
var picNumber = 1;
var timerID;
var i = 0;
var j = 0;
var playing = false;
var imageDescString;
var imageSrcString;

function pauseRotation () {
  clearTimeout (timerID);
  playing = false;
}
function playRotation (picAmount,imageSrc,imageDesc) {
 document.getElementById('picProperty').style.display = "block";
 document.getElementById('picCaption').style.display = "block";
 imageSrc_array=imageSrc.split("|");
 imageDesc_array= getHTMLDecode(imageDesc).split("|");
 imageDescString = imageDesc;
 imageSrcString = imageSrc;
 if (playing == false) {
    doRotation (picAmount,imageSrc,imageDesc);
 }
}
function doRotation (picAmount, imageSrc, imageDesc) {
    clearTimeout (timerID);
	if (j >= picAmount) j = 0;
	document.getElementById('picProperty').src = imageSrc_array[j];
	document.getElementById('picCaption').innerHTML = imageDesc_array[j];
	updatePicNumbers();
	
    picNumber = picNumber + 1
    if (picNumber > picAmount) picNumber = 1;
    j = j + 1
    timerID = setTimeout("doRotation('"+picAmount+"','"+imageSrc+"','"+imageDesc+"')", 6000);
    playing = true;
  
  }
function goToPage (imageSrc,imageDesc,newNumber) {
	picNumber = newNumber;
    document.getElementById('picProperty').src = imageSrc;
	document.getElementById('picCaption').innerHTML = getHTMLDecode(imageDesc);
	updatePicNumbers();
	pauseRotation ();
    playing = false;
    j = newNumber - 1;
  }
  
function goToExecute (picAmount, imageSrc,imageDesc) {
  if (playing == false) {

    j = j + 1
    if (j >= picAmount) j = 0;
    document.getElementById('picProperty').src = imageSrc_array[j];
	document.getElementById('picCaption').innerHTML = imageDesc_array[j];

    picNumber = picNumber + 1
    if (picNumber > picAmount) picNumber = 1;
	updatePicNumbers();
  }

  if (playing == true) doRotation(picAmount, imageSrcString ,imageDesc);
}

function goToNext (picAmount) {
  goToExecute(picAmount, imageSrcString ,imageDescString);
  pauseRotation ();
}

function goToPrevious (picAmount) {
  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, imageSrcString, imageDescString);
  pauseRotation ();
}

function updatePicNumbers()
{
    document.getElementById('HomeContent1_btnOne').className = "";
	document.getElementById('HomeContent1_btnTwo').className = "";
	document.getElementById('HomeContent1_btnThree').className = "";
	if (picNumber == 1)	document.getElementById('HomeContent1_btnOne').className = "thepage";
	if (picNumber == 2)	document.getElementById('HomeContent1_btnTwo').className = "thepage";
	if (picNumber == 3)	document.getElementById('HomeContent1_btnThree').className = "thepage";
}

function getHTMLDecode(t) {
    while (t.indexOf("~singleQuote") > -1)
	{
		t = t.replace("~singleQuote~", "'");
	}
	t = t.replace(/&amp;/g,"&").replace(/&quot;/g,"\"").replace(/&lt;/g,"<").replace(/&gt;/g,">");
	return t
}