//	In association with slidesautoVx.js, this function swaps out slides by fading out the old slide
//	while increasing the alpha level of the new.  It uses the Document Object Model to produce this effect.
//	It works in recent versions of IE and Mozilla.  Opera doesn't yet support the opacity property and the
//	slides just make a straight transition.  	Colin Williams November 2006
//	This version has all comments removed to reduce file size.  If you would like
//	to use this program, please contact me at info@swcsl.com to obtain the "documented" version
var swappingcomplete;
var newX, newY, oldX, oldY;
var alphaval;
var alphadelta = 0.05;
function swapSlides(thisImage, nextImage, framewidth, frameheight, count, delay) {
	if (!document.getElementById || !document.getElementsByTagName  || !document.createElement) return true;
	if (!document.getElementById("mainSlide")) return true;
	var slideholder = document.getElementById("mainSlide");
	if (!slideholder.getElementsByTagName("img")) {
		slideholder.style.height = (boxHeight + 4) + "px";
		slideholder.style.width = (boxWidth + 4) + "px";
		slideholder.style.overflow = "hidden";
		var slideLeft, slideTop;
		slideLeft = Math.floor((framewidth - photoWidth[nextImage]) / 2);
		slideTop = Math.floor((frameheight - photoHeight[nextImage]) / 2);
		var slide = document.createElement("img");
		slide.setAttribute("src",photoList[nextSlide]);
		slide.setAttribute("alt","slide show image");
		slide.style.position = "absolute";
		slide.style.top = slideTop + "px";
		slide.style.left = slideLeft + "px";
		slide.style.height = (photoHeight[nextSlide]) + "px";
		slide.style.width = (photoWidth[nextSlide]) + "px";
		slide.style.borderTop = "2px solid #C8C7D4";
		slide.style.borderLeft = "2px solid #C8C7D4";
		slide.style.borderBottom = "2px solid #91919A";
		slide.style.borderRight = "2px solid #91919A";
		slideholder.appendChild(slide);
		return true;	
	} else {
		if (count <= 1) {
			images = slideholder.getElementsByTagName("img");
			if (images.length != 1) {
				for(var i = 1; i < images.length; i++) {
					slideholder.removeChild(images[i]);
				}
			}
			swappingcomplete = false;
			newX = Math.floor((framewidth - photoWidth[nextImage]) / 2);
			newY = Math.floor((frameheight - photoHeight[nextImage]) / 2);
			oldX = Math.floor((framewidth - photoWidth[thisImage]) / 2);
			oldY = Math.floor((frameheight - photoHeight[thisImage]) / 2);
			var slide = document.createElement("img");
			slide.setAttribute("src",photoList[nextSlide]);
			slide.setAttribute("alt","slide show image");
			slide.style.position = "absolute";
			slide.style.top = newY + "px";
			slide.style.left = newX + "px";
			slide.style.height = (photoHeight[nextSlide]) + "px";
			slide.style.width = (photoWidth[nextSlide]) + "px";
			slide.style.borderTop = "2px solid #C8C7D4";
			slide.style.borderLeft = "2px solid #C8C7D4";
			slide.style.borderBottom = "2px solid #91919A";
			slide.style.borderRight = "2px solid #91919A";
			slide.style.filter = "alpha(opacity = 0)";
			slide.style.MozOpacity = "0";	
			alphaval = 0;
			slideholder.appendChild(slide); 
			return false; 
		} else {
			images = slideholder.getElementsByTagName("img");
			alphaval += alphadelta;
			if(alphaval >= 1) {
				alphaval = 1;	
				images[1].style.filter = "alpha(opacity = " + Math.ceil(100 * alphaval) + ")";
				images[1].style.MozOpacity = alphaval;
				slideholder.removeChild(images[0]);
				swappingcomplete = true;
			} else {
				images[1].style.filter = "alpha(opacity = " + Math.ceil(100 * alphaval) + ")";
				images[1].style.MozOpacity = alphaval;
				images[0].style.filter = "alpha(opacity = " + Math.ceil(100 * (1 - alphaval)) + ")";
				images[0].style.MozOpacity = (1 - alphaval);
			}
			if (swappingcomplete == true) {
				swappingcomplete = false;
				return true;
			} else {
				return false;
			}
		}
	}
}
