var slideshowCurrent;
var slideshowLast;
var slideshowImages;
var imageLength;
var slideshowSlider;
var pixelsmove;
var buttonsUsed = false;
function loadSlideshow () {
	slideshowCurrent = 0;
	imageLength = 790;
	pixelsmove = 100;
	slideshowImages  = document.getElementById("slides").getElementsByTagName("div");
	slideJumpButtons = document.getElementById("slideJump").getElementsByTagName("button");
	slideshowButtonForward  = document.getElementById("slideshowForward");
	slideshowButtonBack  = document.getElementById("slideshowBack");
	slideshowSlider = document.getElementById("slides");
	
	// apply slide styles
	slidesCount = slideshowImages.length;
	document.getElementById("slideWrapper").style.position='relative';
	/*
	slideshowSlider.style.position='absolute';
	slideshowSlider.style.width=(slideshowImages.length*imageLength)+"px";
	slideshowSlider.style.left=0+"px";
	*/
	if (slidesCount != null) {
		for(i=1;i<slidesCount;i++) {
			slideshowImages[i].style.position = "absolute";
			slideshowImages[i].style.display = "none";
			slideshowImages[i].xOpacity = 0;
		}
	}
	slideshowImages[0].xOpacity = .99;
	checkButtons();
	setTimeout(timed_slideshow,4000);
}
function timed_slideshow() {
	if (!buttonsUsed) {
		slideshowLast=slideshowCurrent;
		slideshowCurrent++;
		if (slideshowCurrent == slideJumpButtons.length) {
			slideshowCurrent = 0;
		}
		slideshowAnimate();
		checkButtons();
		setTimeout(timed_slideshow,4000);
	}
}
function checkButtons() {
	for(i=0;i<slideJumpButtons.length;i++) {
		if (i == slideshowCurrent) {
			slideJumpButtons[i].className = "active";
		} else {
			slideJumpButtons[i].className = "none";
		}
	}
}
function slideshowGoForward() {
	//alert(slideshowSlider.style.left.replace("px",""));
	/*if ((slideshowCurrent+1) < slideshowImages.length) {
		slideshowImages[slideshowCurrent].style.display = "none";
		slideshowCurrent++;
		slideshowImages[slideshowCurrent].style.display = "block";
	}
	*/
	buttonsUsed = true;
	slideshowLast=slideshowCurrent;
	slideshowCurrent++;
	if (slideshowCurrent == slideJumpButtons.length) {
		slideshowCurrent = 0;
	}
	slideshowAnimate();
	checkButtons();
}
function slideshowGoBack() {
	/*
	if ((slideshowCurrent-1) >= 0) {
		slideshowImages[slideshowCurrent].style.display = "none";
		slideshowCurrent--;
		slideshowImages[slideshowCurrent].style.display = "block";
	}*/
	buttonsUsed = true;
	slideshowLast=slideshowCurrent;
	if (slideshowCurrent <= 0) {
		slideshowCurrent = slideJumpButtons.length;
	}
	slideshowCurrent--;
	slideshowAnimate();
	checkButtons();
}
function slideshowJump(slide) {
	/*
	slide = (slide.innerHTML-1);
	if ((slide) >= 0 && slide < slideshowImages.length) {
		slideshowImages[slideshowCurrent].style.display = "none";
		slideshowCurrent=slide;
		slideshowImages[slide].style.display = "block";
	}*/
	buttonsUsed = true;
	slideshowLast=slideshowCurrent;
	slideshowCurrent=(slide.innerHTML-1);
	slideshowAnimate();
	checkButtons();
}
function slideshowAnimate () {
	/*
	This is the slide animation for this slideshow
	slideLocation = -slideshowCurrent*imageLength;
	sliderLeft = parseInt(slideshowSlider.style.left);
	pixelsmovetemp = pixelsmove;
	if (slideLocation <= sliderLeft) {
		if (Math.abs(slideLocation-sliderLeft) < pixelsmovetemp) {
			slideshowSlider.style.left=slideLocation+"px";
			return;
		}
		slideshowSlider.style.left=(sliderLeft-pixelsmovetemp)+"px";
		setTimeout(slideshowAnimate,50);
	}
	if (slideLocation >= sliderLeft) {
		if (Math.abs(slideLocation-sliderLeft) < pixelsmovetemp) {
			slideshowSlider.style.left=slideLocation+"px";
			return;
		}
		slideshowSlider.style.left=(sliderLeft+pixelsmovetemp)+"px";
		setTimeout(slideshowAnimate,50);
	}
	*/
	for(i=0;i<slidesCount;i++) {
		if (slideshowImages[i] && i != slideshowLast && i!= slideshowCurrent) {
			slideshowImages[i].style.display = "none";
			slideshowImages[i].xOpacity = 0;
		}
	}
	cOpacity = slideshowImages[slideshowLast].xOpacity;
	nOpacity = slideshowImages[slideshowCurrent].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	slideshowImages[slideshowCurrent].style.display = "block";
	slideshowImages[slideshowLast].xOpacity = cOpacity;
	slideshowImages[slideshowCurrent].xOpacity = nOpacity;
	
	setOpacity(slideshowImages[slideshowLast]);
	setOpacity(slideshowImages[slideshowCurrent]);
	
	if(cOpacity<=0) {
		slideshowImages[slideshowLast].style.display = "none";
		slideshowImages[slideshowCurrent].xOpacity = .99;
		setOpacity(slideshowImages[slideshowCurrent]);
	} else {
		setTimeout(slideshowAnimate,50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
}