var currentPicture = 1;
var totalPictures = 7;

var pictureDescription = new Array(8); 
pictureDescription[0] = ""; 
pictureDescription[1] = "Yes I am little!"; 
pictureDescription[2] = "Why does that thing you are holding keep flashing like that?";
pictureDescription[3] = "You taste like SaUsAgEs buddy!";
pictureDescription[4] = "Please don't eat me mister.";
pictureDescription[5] = "My Mom and Dad.";
pictureDescription[6] = "Woof WOOOOOOOOOOOOOOOOOOOOOF! RAARRRWWRR! ;)";
pictureDescription[7] = "My uncle Bailey as a puppy!";

function checkNumeric()
{
	var key = window.event.keyCode;
	theString = String.fromCharCode(key);
	if ( key > 47 && key < 58 ) return;
   	else
   	{
   		changeAlert("<b>'" + theString + "' is <i>NOT</i> a number. Please try again.</b>");
   		window.event.returnValue = null;
   	}
}

function getElement(id)
{
	return document.getElementById ? document.getElementById(id) : document.all ? document.all(id) : null;
}

function changeCounter(counterNumber)
{
	var anElement = getElement("theCounter");
	if (anElement && typeof anElement.innerHTML != 'undefined') 
	{
		anElement.innerHTML = "Puppy Photo #" + counterNumber + " of "+ totalPictures +".";
	}
}

function changeMessage(theMessage)
{
	var anElement = getElement("theMessage");
	if (anElement && typeof anElement.innerHTML != 'undefined') 
	{
		anElement.innerHTML = theMessage;
	}
}

function changeAlert(alertMessage)
{
	var anElement = getElement("anAlert");
	if (anElement && typeof anElement.innerHTML != 'undefined') 
	{
		anElement.innerHTML = alertMessage;
	}
}

function home()
{
	currentPicture = 1;
	document.PuppyPhotos.thePicture.src = "/images/PuppyPhotos/" + currentPicture + ".jpg";
	changeCounter(currentPicture);
	changeMessage(pictureDescription[currentPicture]);
	changeAlert("&nbsp;");
	document.PuppyPhotos.jumpTo.value = "";
}

function next()
{
	currentPicture++;
	if(currentPicture > totalPictures) currentPicture = 1;
	document.PuppyPhotos.thePicture.src = "/images/PuppyPhotos/" + currentPicture + ".jpg";
	changeCounter(currentPicture);
	changeMessage(pictureDescription[currentPicture]);
	changeAlert("&nbsp;");
	document.PuppyPhotos.jumpTo.value = "";
}

function previous()
{
	currentPicture--;
	if(currentPicture < 1) currentPicture = totalPictures;
	document.PuppyPhotos.thePicture.src = "/images/PuppyPhotos/" + currentPicture + ".jpg";
	changeCounter(currentPicture);
	changeMessage(pictureDescription[currentPicture]);
	changeAlert("&nbsp;");
	document.PuppyPhotos.jumpTo.value = "";
}

function jumpToPicture()
{
	var imageNumber = document.PuppyPhotos.jumpTo.value;
	
	// Check to make sure the image is in the correct range.
	if ((imageNumber > totalPictures) || (imageNumber < 1))
	{
		changeAlert("<b>Please enter a number between <i>1 and " + totalPictures + "</i>.</b>");
		document.PuppyPhotos.jumpTo.value = "";
	}
	else
	{
		document.PuppyPhotos.thePicture.src = "/images/PuppyPhotos/" + imageNumber + ".jpg";
		changeCounter(imageNumber);
		changeMessage(pictureDescription[document.PuppyPhotos.jumpTo.value]);
		changeAlert("&nbsp;");
		document.PuppyPhotos.jumpTo.value = "";
	}
}