
var interval = 2.5; // delay between rotating images (in seconds)
var direction = "down"; // "down" or "up" - assuming a non-random display
var random_display = 0; // 0 = no, 1 = yes
interval *= 1000;

var image_index = 0;
image_list = new Array();
image_list[image_index++] = "480frnt.jpg";
image_list[image_index++] = "280FXPanel.JPG";
image_list[image_index++] = "480vis3.jpg";
image_list[image_index++] = "BRIEFING2.JPG";
image_list[image_index++] = "CIMG0028.JPG";
image_list[image_index++] = "DSC00089.JPG";
image_list[image_index++] = "DSC00090.JPG";
image_list[image_index++] = "Dual.JPG";
image_list[image_index++] = "dz2.JPG";
image_list[image_index++] = "EnstromF28.jpg";
image_list[image_index++] = "eyecab.jpg";
image_list[image_index++] = "F28FWe.jpg";
image_list[image_index++] = "f28police.jpg";
image_list[image_index++] = "G-BEYA.JPG";
image_list[image_index++] = "G-BGWS.JPG";
image_list[image_index++] = "G-BONG.JPG";
image_list[image_index++] = "G-BRCP2.JPG";
image_list[image_index++] = "g-brpo2.jpg";
image_list[image_index++] = "G-BSAU2.JPG";
image_list[image_index++] = "g-bsie1.JPG";
image_list[image_index++] = "G-BSLV.JPG";
image_list[image_index++] = "G-BWMD2.JPG";
image_list[image_index++] = "G-BWSK.JPG";
image_list[image_index++] = "G-BWSK2.JPG";
image_list[image_index++] = "G-DORBI.JPG";
image_list[image_index++] = "G-IJBB.JPG";
image_list[image_index++] = "G-LADD.JPG";
image_list[image_index++] = "g-liva1.JPG";
image_list[image_index++] = "G-LIVR.JPG";
image_list[image_index++] = "G-MHCB2.JPG";
image_list[image_index++] = "g-mhcd.JPG";
image_list[image_index++] = "g-mhce.JPG";
image_list[image_index++] = "G-MHCJ.JPG";
image_list[image_index++] = "G-MHCK.JPG";
image_list[image_index++] = "G-OJBB.JPG";
image_list[image_index++] = "G-OSAB.JPG";
image_list[image_index++] = "g-shaa1.jpg";
image_list[image_index++] = "G-SHAA2.JPG";
image_list[image_index++] = "G-SNAZ.JPG";
image_list[image_index++] = "g-sp.jpg";
image_list[image_index++] = "GUAY2.jpg";
image_list[image_index++] = "GUAYINST.jpg";
image_list[image_index++] = "Hover.JPG";
image_list[image_index++] = "N8627e.jpg";
image_list[image_index++] = "Picture002.jpg";
image_list[image_index++] = "Picture003.jpg";
image_list[image_index++] = "Picture102.jpg";
image_list[image_index++] = "Preflight.JPG";
image_list[image_index++] = "REDF28B.JPG";
image_list[image_index++] = "VRTXwithMerlin.jpg";
image_list[image_index++] = "G-WIZI1.jpg";
image_list[image_index++] = "G-LADZ015.jpg";
image_list[image_index++] = "G-MOTR001.jpg";


var number_of_image = image_list.length;

function imageItem(image_location) {
	this.image_item = new Image();
	this.image_item.src = image_location;
}
	
function get_ImageItemLocation(imageObj) {
	return(imageObj.image_item.src)
}
	
function generate(x, y) {
	var range = y - x + 1;
	return Math.floor(Math.random() * range) + x;
}

function getNextImage() {
	if (random_display) {
		image_index = generate(0, number_of_image-1);
	}
	else {


		if("up" != direction) {
			image_index = (image_index+1) % number_of_image;
		} else {
			if(0 == image_index) { // the modulus stuff didn't seem to work going down the images, so have done it the long way...
				image_index = number_of_image - 1;
			} else {
				image_index = image_index - 1;
			}
		}
	}
	var new_image = get_ImageItemLocation(new imageItem("images/gallery/thumbnails/" + image_list[image_index]));
	return(new_image);
}

function rotateImage(place, newDirection) {
	direction = newDirection;
	switch(place) {
		case "rImage":
			var new_image = getNextImage();
			document[place].src = new_image;
			document.getElementById("gallerypreviewlink").href = ('home/gallery/' + image_index);
			break;
		case "gImage":

			if(image_list.length == image_index) {
				image_index = 3;
			}
			
//			alert(image_index);
			if("up" == direction) {
				for (i=8;i>=1;i--) {
					if(0 == image_index) { // the modulus stuff didn't seem to work going down the images, so have done it the long way...
						image_index = number_of_image - 1;
					} else {
						image_index = image_index - 1;
					}
				}
				direction = "down";
			}

			for (i=1;i<=4;i++) {
				var new_image = getNextImage();
//					alert(image_index + " " + place + i);
				document[place + i + ""].src = new_image;
//				document.getElementById("gallerylink" + i).href = ('images/gallery/' + image_list[image_index]);
				document.getElementById("gallerylink" + i).href = ("javascript:changeMainToMe('"+ image_list[image_index] + "')");
			}
			break;

//			alert("finished " + image_index);
	
	}
		
//	var recur_call = "rotateImage('"+place+"')";
//	setTimeout(recur_call, interval);
}

function advanceToImage(startImage) {
	image_index = (startImage+7) % number_of_image;
	rotateImage('gImage', 'up');
//	alert("finished " + image_index);
}	

function changeMainToMe(newImage) {
//	alert(newImage)
	document.getElementById("galleryMainImage").src = "images/gallery/" + newImage;
}


