function alanswapImg(image) 
{
  var tempsrc1 = new Image();
	tempsrc1.src = document.getElementById("PICTURE1").src;
  var tempsrc2 = new Image();
	tempsrc2.src = document.getElementById("PICTURE" + image).src;
  var str1 = tempsrc1.src;
  var str2 = tempsrc2.src
  //str1.indexOf("width=555")
  //str1.subString(
  //str1.replace("width=555", "width=180");
  //alert("str1 value: should be 180 now " + str1);
  //str2.replace("width=180", "width=555");
  str1 = myreplace(str1);
  str2 = myreplace(str2);
  document.getElementById("PICTURE1").src = str2;
  document.getElementById("PICTURE" + image).src = str1;
}



function myreplace(s){
  if (/width=555/.test(s)) s=s.replace(/width=555/g,'width=180');
  else if (/width=180/.test(s)) s=s.replace(/width=180/g,'width=555');
  return s;
}

function populateImgArray()
{
	
	var counter = 1;
	//var img = new Image();
	var img;
	for (counter=1;counter<=20;counter++)
	{
		
		if (document.getElementById("PICTURE" + counter) != null) 
		{
			img = document.getElementById("PICTURE" + counter).src;
			img = myreplace(img);
			imgArray[counter-1] = img;
		}
		else 
		{
			counter = 20;
		}
	}

	

	document.getElementById("imageCount").innerHTML = "Showing image " + (imgCounter+1) + " of " + imgArray.length;
}


function nextImage()
{
	if (imgArray.length > 0)
	{
		var tempImageSRC;
		var tempMainImageSRC;
		if ((imgCounter + 1) == (imgArray.length))
		{
			alert("You have reached the end of the images");
		}
		else
		{
			imgCounter = (imgCounter + 1);	
			tempImageSRC = imgArray[imgCounter];
			document.getElementById("MAINPICTURE").src = tempImageSRC; 
			document.getElementById("imageCount").innerHTML = "Showing image " + (imgCounter+1) + " of " + imgArray.length;
		}
	}
	else
	{
		alert("No images");
	}
}


function previousImage()
{
	if (imgArray.length > 0)
	{
		var tempImageSRC;
		var tempMainImageSRC;
		if (imgCounter == 0)
		{
			alert("You have reached the start of the images");
		}
		else
		{
			imgCounter = (imgCounter - 1);	
			tempImageSRC = imgArray[imgCounter];
			document.getElementById("MAINPICTURE").src = tempImageSRC; 
			document.getElementById("imageCount").innerHTML = "Showing image " + (imgCounter+1) + " of " + imgArray.length;
		}
	}
	else
	{
		alert("No images");
	}
}

function getImageCount()
{
	return imgArray.length;
}

function getCounter()
{
	return imgCounter;
}
	