/**********************************************************************
 *	IMAGE ROTATION                                                    *
 *	Change history:                                                   *
 *	- navigation and captions disabled on line 117                    *
 **********************************************************************/

document.body.onload = runSlideShowParent;

doclay = (document.layers)? true : false
docall = (document.all)? true : false
docget = (document.getElementById)? true : false

// Set the slideshow speed (in milliseconds)
var SlideShowSpeed = 10000;

// Set the duration of crossfade (in seconds)
var CrossFadeDuration = 3;

// Set the order of display: "linear" or "random"
var SlideShowOrder = "random";

var currentImg;
var total;

thisImg = 0
imgCt = (imageLocation.length - 1);
baseCt = 0

imageCaption = new Array()

imageCaption[0] = "<b>Lorem ipsum dolor sit amet</b><br>Consectetuer adipiscing elit. Praesent tempus leo sit amet tellus. Quisque adipiscing ultricies felis. Ut vel purus sit amet dui rhoncus varius."
imageCaption[1] = "<b>Nulla rhoncus mi ut magna</b><br>Vestibulum fermentum mi aliquet eros. Aenean imperdiet pulvinar felis. Proin ullamcorper nibh non sapien. Pellentesque dui. Integer in nisi non enim gravida pharetra."
imageCaption[2] = "<b>Sed dolor diam, malesuada egestas</b><br>Vivamus imperdiet tortor vitae dui. Nullam elementum. Sed congue lectus ac est. Proin ullamcorper nibh non sapien."

imageNavigation = new Array()

imageNavigation[0] = "<span class=\"slideshow-on\">1<\/span> . <a href=\"javascript:StartorStop(0);(thisImg=1);layerWrite(\'imageDiv\')\">2<\/a> . <a href=\"javascript:StartorStop(0);(thisImg=2);layerWrite(\'imageDiv\')\">3<\/a>"
imageNavigation[1] = "<a href=\"javascript:StartorStop(0);(thisImg=0);layerWrite(\'imageDiv\')\">1<\/a> . <span class=\"slideshow-on\">2<\/span> . <a href=\"javascript:StartorStop(0);(thisImg=2);layerWrite(\'imageDiv\')\">3<\/a>"
imageNavigation[2] = "<a href=\"javascript:StartorStop(0);(thisImg=0);layerWrite(\'imageDiv\')\">1<\/a> . <a href=\"javascript:StartorStop(0);(thisImg=1);layerWrite(\'imageDiv\')\">2<\/a> . <span class=\"slideshow-on\">3<\/span>"

var tss;
var iss;
var thisImg = 0;
var start = 1;

//variable is set to 1 initially so that slideshow starts when page is loaded
//vairable is set to 0 if PREVIOUS or NEXT is clicked which stops the slideshow
function StartorStop(x) {
start = x;
}

//preloads images into an array
var preLoad = new Array();
for (iss = 0; iss < imgCt+1; iss++){
preLoad[iss] = new Image();
preLoad[iss].src = imageLocation[iss];}

//this function is run first so that there is a delay on the first image
//otherwise the slideshow jumps to the second image immediately
//timer is faster for this than the loop
function runSlideShowParent(){
tss = setTimeout('runSlideShow()', SlideShowSpeed);
}

function initSlideShow(){

	if(SlideShowOrder=="random"){
		var randomnumber = Math.floor(Math.random() * (imgCt + 1));
		thisImg = randomnumber;
	}
	
	document.write("<img src=\"" + imageLocation[thisImg] + "\" name=\"slider\" id=\"slider\" alt=\"\" border=\"0\">")

}

//this is the automatic slideshow
function runSlideShow(){

	if ( start == 1 ){

		//counter is at beginning so that if user interrupts the slideshow with the PREVIOUS NEXT
		//then the slideshow won't jump ahead two images instead of just one

	navigation = imageNavigation[thisImg]

		if (thisImg >= imgCt){
		thisImg=0;
		navigation = imageNavigation[thisImg]
		} else {
		
		if(SlideShowOrder=="random") {

			var randomnumber = thisImg;
			
			// Prevents the same image beeing displayed two times in a row
			while(randomnumber==thisImg) { randomnumber = Math.floor(Math.random() * (imgCt + 1)); }
			
			thisImg = randomnumber;

		} else {
			
			thisImg = thisImg + 1;
		}
		
		navigation = imageNavigation[thisImg]
		}

		if (docall){
		document.images.slider.style.filter="blendTrans(duration=2)";
		document.images.slider.style.filter="blendTrans(duration=CrossFadeDuration)";
		document.images.slider.filters.blendTrans.Apply();}
	
	document.images.slider.src = preLoad[thisImg].src; 
	
		if (docget){
		
			// document.getElementById("slidenavigation").innerHTML= navigation;
		
			//document.getElementById("slidertext").innerHTML = imageCaption[thisImg];
		
		} else if (doclay) {
		document.layers["slidenavigation"].document.open()
		document.layers["slidenavigation"].document.write('<table border=0 cellpadding=0 cellspacing=0 width=300><tr><td>')
		document.layers["slidenavigation"].document.write('<span class=slideshow-default>')
		document.layers["slidenavigation"].document.write(navigation)
		document.layers["slidenavigation"].document.write('<\/span>')
		document.layers["slidenavigation"].document.write('<\/td><\/tr><\/table>')
		document.layers["slidenavigation"].document.close()
		document.slider.src = imageLocation[thisImg]
		
		//document.layers["slidertext"].document.open()
		//document.layers["slidertext"].document.write(imageCaption[thisImg])
		//document.layers["slidertext"].document.close()
		
		} else if (docall) {
		document.all.slidenavigation.innerHTML = navigation;
		document.slider.src = imageLocation[thisImg];
		//document.all.slidertext.innerHTML = imageCaption[thisImg];
		}
		
		if (docall) document.images.slider.filters.blendTrans.Play();
		
	tss = setTimeout('runSlideShow()', SlideShowSpeed);
	}
}


//this is the user controlled slideshow
function layerWrite(id,text) {

image = imageLocation[thisImg]
navigation = imageNavigation[thisImg]

	if (thisImg > imgCt) {
	thisImg = 0
	navigation = imageNavigation[thisImg]
	}
	
	if (thisImg < baseCt) {
	thisImg = 5
	navigation = imageNavigation[thisImg]
	}

currentImg = thisImg + 1
total = imgCt + 1

	if (docget) {
		document.getElementById("slidenavigation").innerHTML = navigation;
		document.slider.src = imageLocation[thisImg]
	} else if (doclay) {

		document.layers["slidenavigation"].document.open()
		document.layers["slidenavigation"].document.write('<table border=0 cellpadding=0 cellspacing=0 width=200><tr><td>')
		document.layers["slidenavigation"].document.write('<span class=slideshow-default>')
		document.layers["slidenavigation"].document.write(navigation)
		document.layers["slidenavigation"].document.write('<\/span>')
		document.layers["slidenavigation"].document.write('<\/td><\/tr><\/table>')
		document.layers["slidenavigation"].document.close()
		document.slider.src = imageLocation[thisImg]
	} else if (docall) {
		document.all.slidenavigation.innerHTML = navigation
		document.slider.src = imageLocation[thisImg]
	}

}