var numberOfPictures = 142;

function picture(image, thumb, title, comment) {
	this.image = image;
	this.comment = comment;
	this.thumb = thumb;
	this.title = title;
}

//list of pictures with paired with comments they might have
var xpPictures = new Array(new picture("1a.png", "thumb1a.png", "Five Seconds Old", "4.5 kg and 61 cm"));

while (numberOfPictures > 1) {
	xpPictures[xpPictures.length] = new picture(numberOfPictures + ".jpg", "thumb" + numberOfPictures-- + ".png", "", "");
}

function randomIndex()
{
	var z = Math.floor(Math.random()*pix.length);
	return z;
}

// build all pictures
function buildPictures() {
	var picturePage = "";
	for (var i = 0; i < xpPictures.length; i++) {
		picturePage += "<div class = 'img'> <a href = 'images/" + xpPictures[i].image + "' target = '_blank'><img src = 'images/" + xpPictures[i].thumb + "' title = '";
		if(xpPictures[i].title == "" && xpPictures[i].comment == "") {
		}
		else {
			if(xpPictures[i].title == "") {
				picturePage += xpPictures[i].comment;
			}
			else {
				if(xpPictures[i].comment == "") {
					picturePage += xpPictures[i].title;
				}
				else {
					picturePage += xpPictures[i].title + ":" + xpPictures[i].comment;
				}
			}
		}
		picturePage += "' /></a></div>";
	}
	return picturePage;
}

// set's the page
function setPictures() {
	document.getElementById("alexanderRupert").innerHTML = buildPictures();
}

// sets three pictures at random
function setPic()
{
	// start by assuming at least two of the pictures are the same
	var different = false;
	
	// loads three random picture index numbers, may be the same
	var image1 = randomIndex();
	var image2 = image1;
	var image3 = image1;
	
	// compare image1 to image2 and change image2 if they are the same
	while(different == false)
	{
		// sets the different flag to true if the two are not the same
		if(image2 != image1)
		{
		different = true;
		}
		else image2 = randomIndex();
	}
		
	// resets the different flag
	different = false;

	// compares image3 to both image1 and image2
	while(different == false)
	{
		//chooses a new image3 for this iteration
		image3 = randomIndex();
		
		// if image3 is different from image1 the different flag becomes true
		if(image3 != image1)
		{
		different = true;
		}
			
		// if image 3 is the same as image2 the different flag becomes false
		if(image3 == image2)
		{
		different = false;
		}
	}
	
	// puts the images in their places
	document.leftPix.src = pix[image1].image;
	document.centerPix.src = pix[image2].image;
	document.rightPix.src = pix[image3].image;
	
	//puts the comments in their places
	//????	
}