//gcs 2006 original JS



// this is the slide show initiation function | starts the interval between crossfades, sets the main variables

function autoSlides (topID, backTag, fromTop, slideDuration, slideTotal, fadeDuration, imageFolder) {
	var targetTop = document.getElementById(topID);
	var targetBack = document.getElementsByTagName(backTag).item(0);

// all except Explorer
	if (self.innerHeight) {
		var speed = 1000 * slideDuration;
		setPath(imageFolder);

		if (fadeDuration) {
			var fadeSpeed = (fadeDuration *1000) / 20;//user specified length of time for the crossfade 20 steps
		}
		else {
			var fadeSpeed = 50; //default to 1 second for crossfade
		}

		if(typeof this.currentNumber == 'undefined') {
			this.currentNumber=1;
		}

		firstRun(topID, backTag, fromTop); //set the opacity for the first crossfade

		//begin the interval for crossfading images set the floating variable
		setInterval( function(){
			crossfade(topID, backTag, slideTotal, fadeSpeed);
			}, speed);

		}
		
	// Explorer 6 Strict Mode
	else if (document.documentElement && document.documentElement.clientHeight) {
		var speed = 1000 * slideDuration;
		setPath(imageFolder);

		if (fadeDuration) {
			var fadeSpeed = (fadeDuration *1000) / 20;//user specified length of time for the crossfade 20 steps
		}
		else {
			var fadeSpeed = 50; //default to 1 second for crossfade
		}

		if(typeof this.currentNumber == 'undefined') {
			this.currentNumber=1;
		}

		firstRun(topID, backTag, fromTop); //set the opacity for the first crossfade

		//begin the interval for crossfading images set the floating variable
		setInterval( function(){
			crossfade(topID, backTag, slideTotal, fadeSpeed);
			}, speed);

		}
		
	
	else {
		//maybe get random
		//alert('firefox is best');
	}
}

//by ID  -- crossfade the images loop the timeouts for opacity
function crossfade(topID, backTag, slideTotal, fadeSpeed) {
	for (i=1; i<21; i++) {
		setTimeout('setOpacity(' + i + ',"' + topID + '","' + backTag + '",' + slideTotal + ')', fadeSpeed*i);
	}
}

function setPath(imageFolder) {
	if(typeof this.thePath == 'undefined') {
		if (imageFolder) {
			this.thePath = imageFolder;
		}
		else {
			this.thePath = '..\/graphics\/slide_';
		}	
	}
}


//set the opacity from the timeout calls and if they hit the last step call the restacker
function setOpacity(myValue, topID, backTag, slideTotal) {
	var trans1 = myValue/20
	var trans2 = myValue*5
	
	document.getElementById(topID).style.opacity = trans1;
	document.getElementById(topID).style.filter = 'alpha(opacity=' + trans2 + ')';
		
	if (myValue >= 20) {

		document.getElementById(topID).style.opacity = 1;
		document.getElementById(topID).style.filter = 'alpha(opacity=' + 100 + ')';
		restackImages (topID, backTag, slideTotal);
	}
}

// first time the function is called set the opacity for the top ID (maybe swap image in)
function firstRun(topID, backTag, fromTop) {
	var targetElement = document.getElementById(topID).style;
	
	// get the width of the initial iage
	myImage = new Image();
	myImage.src = thePath + '0.jpg';
	var newW = myImage.width.toString();
	var newH = myImage.height.toString();
	
	var wide = newW + 'px';
	var high = newH + 'px';
	
	//get the position for the over image
	if (fromTop) {
		var newY = fromTop;
	}
	else {
		var newY = 10;
	}
	
	
	//setting the various CSS style elements for the top element
	targetElement.position = 'absolute';
	targetElement.opacity = 0;
	targetElement.filter = 'alpha(opacity=' + 0 + ')';
	targetElement.zIndex = 2;
	targetElement.top = newY + "px";
	targetElement.styleFloat = "left";
	targetElement.cssFloat = "left";
	targetElement.width = wide;
	targetElement.paddingTop = high;
	targetElement.overflow = 'hidden';
	targetElement.background = 'url(' + thePath + currentNumber +'.jpg)';
	targetElement.backgroundRepeat = 'no-repeat';
	
	
}

function restackImages(topID, backTag, slideTotal) {
	var targetTop = document.getElementById(topID);
	var targetBack = document.getElementsByTagName(backTag).item(0);
	
	if (currentNumber >= slideTotal -1) {
		var nextNum = 0;
	}
	else {
		var nextNum = currentNumber+1;
	}
	
	setBack(topID, backTag, nextNum, slideTotal);
	setTop(topID, backTag, nextNum);
	
	currentNumber = nextNum;
	}

function setTop(topID, backTag, nextNum) {
	
	setTimeout( function(){
	var nPath = 'url(' + thePath + nextNum + '.jpg)';
	document.getElementById(topID).style.background = nPath;	
	}, 1000);

}

function setBack(topID, backTag, nextNum, slideTotal) {
	if (nextNum == 0){
		var oldNum = slideTotal -1;
	}
	else {
		var oldNum = nextNum -1;
	}
	var nPath = 'url(' + thePath + oldNum + '.jpg)';
	document.getElementsByTagName(backTag).item(0).style.background = nPath;
	
	setTimeout( function(){
		setOpacity(0, topID, 1000);
	}, 500);
}


