// functions below build a sliding gallery
// originally derived from gallery at http://www.gilesrevell.com/
// modified by Jan Mickinn www.mickinn.de

// variables to set
x = 0;
xTarget = 0;
currentImage = "";
currentImageAID = "";
selectedImage = "";
move_timeout = null;
scrolling = false;
prevImage = null;
nextImage = null;
loadQueue = new Array();
widths = new Array();
// set the first width as 0
widths[0] = 0;
// space between images (see space in CSS around div.image)
space = 0;
// tell it not to go until its loaded
ready = 0;
// browser check
if (navigator.appName.indexOf("Microsoft")!=-1&&parseInt(navigator.appVersion)>=4) {
	var ie = 1;
	if (window.XMLHttpRequest) {
		// IE 7, mozilla, safari, opera 9
		space = 0;
	} else {
	// IE6, older browsers
		space = 0;
	}
}
else {
	var ie = null;
}

function move() {
	scrolling = true;
	var xDiff = xTarget - x;
	x += xDiff/4;
	document.getElementById("images").style.left = x + "px";
	if (Math.round(xDiff) == 0) {
		window.clearTimeout(move_timeout);
		move_timeout = null;
		scrolling = false;
	} else {
		move_timeout = window.setTimeout("move();",25);
	}
}

function scrollTo() {
	// here, we make sure we don't scroll unless all the images are loaded
	if (ready == 1 || selectedImage == "") {
		// check to make sure the image is called, if not, it's the first image
		if (selectedImage == "") {
			selectedImage = currentImage;
		}
		//e = document.getElementById(selectedImage);
		var n = currentImage;
		xTarget = Math.round(n * 645) * -1;
		move();
	}
	else {
		//loadImages();
	}
}



// wrapper functions
function rollPrevious() {
	if (currentImage>0)
		currentImage--;
}
function rollNext() {
	if (currentImage)
	{
		if (currentImage+1<images_array.length)
			currentImage++;
	}
	else currentImage=1;
}

function preloadImages() {
	var n = 0;
	var widthsTotal = 0;
	// parse through all the images and ensure that their widths are
	// in the width array
	while (n < images_array.length) {
		// create a new image and then determine its width
		var newImg = new Image();
		newImg.src = folder + images_array[n];
		var theWidth = newImg.width;
		if (!theWidth) {
			theWidth = (document.getElementById('imageDiv' + images_array[n])) ? (document.getElementById('imageDiv' + images_array[n]).style.width.replace(/px/,"")) * 1 : 0;
		}
		n++;
		// figure out the width including space
		var thespace = widths[n-1] + theWidth + space;
		// put the width in the array
		widths[n] = thespace;
		widthsTotal = (thespace + widthsTotal);
	}
	// parse through every image - already loaded - and stuff... 
	ready = 1;
	document.getElementById('imagesOuterA').style.display = "";
	document.getElementById('images').style.width = n * 646 + "px";
}


function preloadImagesNoResize() {
	var n = 0;
	var widthsTotal = 0;
	// parse through all the images and ensure that their widths are
	// in the width array
	while (n < images_array.length) {
		// create a new image and then determine its width
		var newImg = new Image();
		newImg.src = folder + images_array[n];
		var theWidth = newImg.width;
		//if (!theWidth) {
			//theWidth = (document.getElementById('imageDiv' + images_array[n])) ? (document.getElementById('imageDiv' + images_array[n]).style.width.replace(/px/,"")) * 1 : 0;
		//}
		n++;
		// figure out the width including space
		var thespace = widths[n-1] + theWidth + space;
		// put the width in the array
		widths[n] = thespace;
		widthsTotal = (thespace + widthsTotal);
	}
	// parse through every image - already loaded - and stuff... 
	ready = 1;
	document.getElementById('imagesOuterA').style.display = "";
	document.getElementById('images').style.width = n * 646 + "px";
}

