
/* 
 * Change the 5 values below according to the number of
 * images in each directory.
 */
 var adultTotal    = 4;
 var childrenTotal = 15;
 var youthTotal    = 11;
 var generalTotal  = 12;

 var img1 = 'BLANK';
 var img2 = 'BLANK';
 var img3 = 'BLANK'; //the image tags
 var blankImage = '<img src=\"/images/spacer.gif\" width=\"120\" height=\"95\" border=\"0\" hspace=\"0\" vspace=\"0\">';
 var cat1, cat2, cat3;


/**
 * Returns the total that is in the specified category.
 */
function getTotal(category) {
	var total = 0;
	//set total to correct for its category
	switch(category) {
		case 'adult':
			total =adultTotal;
			break;
		case 'children':
			total = childrenTotal;
			break;
		case 'youth':
			total = youthTotal;
			break;
		case 'general':
			total = generalTotal;
			break;
		case 'blank':
			total = 0;
			break;
	} //end of switch
	
	return total;
} //end of getTotal


/**
 * Creates and returns the image name based on the random number
 * that is passed as a parameter
 */
function getNumString(num) {
	var imageNm = 'BLANK';
	if(num < 10)
		imageNm = '100' + num;
	else if(num < 100)
		imageNm = '10' + num;
	else
		imageNum = '1' + num;
	
	return imageNm;
} //of getNumString


/**
 * Creates a random image based on the three 
 * category parameters that are passed.
 */
function randomImage(cat1, cat2, cat3) {
	//alert('entering randomImage');
	var rNum1 = 0;  //first random number
	var rNum2 = 0;  //second random number
	var rNum3 = 0;  //third random number
	var total1 = getTotal(cat1);
	var total2 = getTotal(cat2);
	var total3 = getTotal(cat3);
	var imageName1, imageName2, imageName3;
	var frontString = '<img src=\"/images/photos/';
	var backString = '.jpg\" width=\"120\" height=\"95\" border=\"0\" hspace=\"0\" vspace=\"0\">';
	
	//Create image 1
	if(total1 != 0) {
		rNum1 = Math.round((Math.random() * (total1 - 1))) + 1;
		imageName1 = getNumString(rNum1);
		img1 = frontString + cat1 + '/' + imageName1 + backString;
	}
	else 
		img1 = blankImage;
	
	//Create image 2
	if(total2 != 0) {
		rNum2 = rNum1;
		while(rNum1 == rNum2)
			rNum2 = Math.round((Math.random() * (total2 - 1))) + 1;
		imageName2 = getNumString(rNum2);
		img2 = frontString + cat2 + '/' + imageName2 + backString;
	}
	else
		img2 = blankImage;
	
	//Create image 3
	if(total3 != 0) {
		rNum3 = rNum2;
		while((rNum3 == rNum2) || (rNum3 == rNum1))
			rNum3 = Math.round((Math.random() * (total3 - 1))) + 1;
		imageName3 = getNumString(rNum3);
		img3 = frontString + cat3 + '/' + imageName3 + backString;
	}
	else 
		img3 = blankImage;

} //end of randomImage


/* 
 * Returns the image tag based on the number 
 * parameter that is passed in.  This is the 
 * method that is called from where the image
 * is to be displayed.
 */
function showImage(num) {
	if(num == 1)        		//image 1
		document.write(img1);
	else if(num == 2)   		//image 2
		document.write(img2);
	else if(num == 3)   		//image 3
		document.write(img3);
	else          				//blank image
		document.write(blankImage);
}
