/* -----------------------------------------------------------------------------

	Rotation for the homepage images

	-- Note --

	Image location: .../imgs/
	Image naming: img01.jpg, img02.jpg, etc.
	
	To add an image:
	
	(1) Name it using the next image number available.

		Ex/ if the last image is "img11.jpg", name your image "img12.jpg"
	
	(2) Adjust the "num_image_files" variable below to the correct number
	
-----------------------------------------------------------------------------  */

var num_image_files = 10;		// number of rotating images


var home_page_imgs = '<table border="0" cellspacing="0" cellpadding="0">';
home_page_imgs += '<tr><!-- glow above images !--><td colspan="7"><img src="images/glowimg_top.gif" width="632" height="9" alt="" /></td></tr>';
home_page_imgs += '<tr><!-- left glow | 5 images | right glow !--><td><img src="images/glowimg_left.gif" width="11" height="88" alt="" /></td>';

function in_array(val, an_array){

	for(var i=0; i < 5; i++){
		if (an_array[i]==val){
			return true;
		}
	}
	return false;

}

function get_next_img_number(img_num_array){

	// get a random number
	var new_img_num = Math.round(Math.random() * (num_image_files-1)) +1;	// choose a random number from 1 to num_image_files

	if (in_array(new_img_num, img_num_array)==false){		// (1) new image number so return it

		return new_img_num;

	}else{										

		// (2) keep checking the next image number until max number reached
		next_img_num = new_img_num+1;
		while(next_img_num < (num_image_files+1)){
			if (in_array(next_img_num, img_num_array)==true){
				next_img_num++;
			}else{
				return next_img_num;
			}
		}
		
		// (3) keep checking the previous image number until min number reached
		prev_img_num = new_img_num-1;
		while(prev_img_num > 0){
			if (in_array(prev_img_num, img_num_array)==true){
				prev_img_num =prev_img_num-1;
			}else{
				return prev_img_num;
			}
		}
		//alert('orig: ' +new_img_num + '  new: ' +next_img_num + ' prev: '+prev_img_num);
		//return '900';
														
	}
	
}



function shuffle_homepage_images(){

	var num_hm_img_sets = 3;
	var img_num_list = new Array();
	var idx =0;
	var out_str = '';
	while((img_num_list.length) < 5){

		var img_num = get_next_img_number(img_num_list);

		img_num_list[idx]= img_num;
		idx++;

		var img_num_fmt = '' + img_num;
		if (img_num < 10){
			img_num_fmt = '0' + img_num_fmt;
		}
		if (idx==5){	// last image has no right side border
			home_page_imgs += '<td><img src="images/img' + img_num_fmt + '.jpg"  name="homeimg' + img_num_fmt + '" id="homeimg' + img_num_fmt + '" width="118" height="88" alt="" /></td>';

		}else{			// all images except the last one
			home_page_imgs += '<td class="hm_rotate_imgs"><img src="images/img' + img_num_fmt + '.jpg"  name="homeimg' + img_num_fmt + '" id="homeimg' + img_num_fmt + '" width="118" height="88" alt="" /></td>';
		}

	}
	home_page_imgs += '<td><img src="images/glowimg_right.gif" width="11" height="88" alt="" /></td></tr>';
	home_page_imgs += '<tr><!-- glow below images !--><td colspan="7"><img src="images/glowimg_bottom.gif" width="632" height="9" alt="" /></td></tr>';
	home_page_imgs += '</table>';

}

shuffle_homepage_images();


