var ns6=document.getElementById&&!document.all

var imageCount = 0;
var captionBool = false;		//to indicate if the user wants the caption or not

var ar = new Array();

function preload() {
  if (!document.images) return;

  var arguments = preload.arguments;
  for (var i = 0; i < maxImage; i++) {
    ar[i] = new Image();
    ar[i].src = pathName + "img" + i + ".jpg"
  }
}

function nextImage(){

	if (!document.images) return;

	var arguments = nextImage.arguments;

	//if I have more than one argument then the second argument is to indicate which image to display
	if (arguments.length > 1)
	{

		if (arguments[1] == -1) 		// if value is -1 then display previous image
		{
			imageCount = imageCount - 1;
		
			if (imageCount < 0) 		// if value is zero then reset imageCount
				imageCount = maxImage;

		}			
		else
			imageCount = arguments[1];	//otherwise goto the image indicated
		
	}
	else //otherwise it's when the user clicks on the image and it automatically goes to the next image
	{
		
		if (imageCount == maxImage)
			imageCount = 0;
		else
			imageCount = imageCount + 1;
	}	

	//use the preloaded images when doing replacement
//	document.write(pathName + imageCount + ".jpg");
	
	document.images['main-image'].src = pathName + "img" + eval(imageCount+1) + ".jpg";	
		
	if (captionBool)
		setCaption();
}

function resize(width,height)
{	
	this.resizeTo(width,height)
}

function setCaption()
{
	cross_el=ns6? document.getElementById("caption") : document.all.caption
	//cross_el.innerHTML = captionList[imageCount];	
	
	var htmltext = "<SPAN ID=\"caption\" STYLE=width:" + document.images['main-image'].width + "> " + captionList[imageCount] + "</SPAN>";				
	//document.all.caption.outerHTML = htmltext;
	cross_el.outerHTML = htmltext;
	
	//initally when the page loads up and if this funciton is called then that means
	//that caption is available for this page.  Thus set the caption optoin to true.
	captionBool = true;
}

function removeCaption()
{
	cross_el=ns6? document.getElementById("caption") : document.all.caption
	cross_el.innerHTML = "";
	
	cross_el=ns6? document.getElementById("capOption") : document.all.capOption
	cross_el.outerHTML = "<A ID=\"capOption\" HREF=\"javascript:addCaption()\">add caption</A>";
	
	captionBool = false;
}

function addCaption()
{
	cross_el=ns6? document.getElementById("capOption") : document.all.capOption
	cross_el.outerHTML = "<A ID=\"capOption\" HREF=\"javascript:removeCaption()\">remove caption</A>";
	
	captionBool = true;
	
	setCaption();	
}


