var slideCounter = 1

function checkSlideshowSupport()	{
	
	/* check the browser is capable of recognising the DOM objects
	   we need to implement the script - otherwise return false and abandom the slideshow */
	   
	if(!document.getElementsByTagName) return false;
	if(!document.getElementById) return false;
	if(!document.getElementById("slideshow")) return false;
	
	initialImageFadeout = setInterval("FadeOpacity('slideshow', 100, 0, 3000, 10)", 1000)
	
	//setInterval("displaySequentialSlideshow()", 8000)
	
	setTimeout("clearInterval(initialImageFadeout)", 1500)

}


function displayRandomSlideshow()	{	
	
	
	var showThisImage = "library/" + js_slideShowGallery + "/" + slideshowPics[Math.round(Math.random() * (slideshowPics.length-1))] 

	document.getElementById("slideshow").src = showThisImage

	
}



function displaySequentialSlideshow()	{	
	
	
	setTimeout("clearInterval(initialImageFadeout)", 500)

	var showThisImage = "library/" + js_slideShowGallery + "/" + slideshowPics[slideCounter]
	document.getElementById("slideshow").src = showThisImage
	
	image1FadeIn = setInterval("FadeOpacity('slideshow', 0, 100, 1500, 15)", 1500)
	setTimeout("clearInterval(image1FadeIn)", 1800)

	image1FadeOut = setInterval("FadeOpacity('slideshow', 100, 0, 1500, 15)", 6000)
	setTimeout("clearInterval(image1FadeOut)", 7900)	
	

	newBackgroundImage = setInterval("newBackground()", 5000)	
	setTimeout("clearInterval(newBackgroundImage)", 5300)

	
	var showNextImage = "library/" + js_slideShowGallery + "/" + slideshowPics[slideCounter+1]
	
	
	
		if(slideCounter < slideshowPics.length-2) {
	
				slideCounter = (slideCounter + 2)
		}
		
		else	{
			
		slideCounter = 0
		
		}


}


function newBackground() {
	
	
	
	 document.getElementById("slideShowContainer").style.backgroundImage = "url(library/" + js_slideShowGallery + "/" + slideshowPics[slideCounter+1] + ")"

}



function SetOpacity(elem, opacityAsInt)
{
	var opacityAsDecimal = opacityAsInt;
	
	if (opacityAsInt > 100)
		opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
		opacityAsInt = opacityAsDecimal = 0; 
	
	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
	
	elem.style.opacity = opacityAsDecimal;
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (toOpacity - fromOpacity) / steps;
	
	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

    if (stepNum < steps)
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}
