/* Here you make an array with all the URL's of the images you would like to have in your slideshow.*/
var image = new Array("images/postcards/postcard-<?php echo $_POST[SelectedCard] ?>.jpg", "includes/postcard.php")

/* This number is used to refer to a value of the Array and to know what image should be shown next. */
var imgNumber = 1

/* This is the total amount of images you use, it is used to determine if the imgNumber can still grow. */
var numberOfImg = image.length

/* Now it's time to make the functions for the next and previous images */
function previousImage(){
	/* The if statement is used to know if you aren't already at the first image, because if you are, imgNumber may not decrease. */
	if(imgNumber > 1){
		imgNumber--
	}
	else{
		/* If you already are at the first image, and you click the previous button, the slideshow must show the last image. */
		imgNumber = numberOfImg
	}
	/* Load the image into the document. Don't forget to write imgNumber-1, an array always starts from 0! */
	document.slideImage.src = image[imgNumber-1]
}

function nextImage(){
	/* The if statement is used to know if you aren't already at the last image, because if you are, imgNumber may not increase. */
	if(imgNumber < numberOfImg){

		imgNumber++
	}
	else{
		/* If you already are at the last image, and you click the next button, the slideshow must show the first image. */
		imgNumber = 1
	}
	/* Load the image into the document. Don't forget to write imgNumber-1, an array always starts from 0! */
	document.slideImage.src = image[imgNumber-1]
}

/* Now it is time for the code that preloads the images. */

/* Check if your browser supports the Image Object. */
if(document.images){

	/* Create a new Image Object. */
	var image1 = new Image()

	/* Give the source of the image to the Image Object. */
	image1.src = "images/postcards/postcard-<?php echo $_POST[SelectedCard] ?>.jpg"

	/* Repeat this for all the images you would like to preload.
	Make sure that you do not preload too many images, this will make your document load slowly. */
	var image2 = new Image()
	image2.src = "includes/postcard.php"
}

