//create variables
var slides = new Array();
var o = null;
var time = null;
var xfade = null;
var slideNum = null;
var current = 0;

//*****************************************************************

//get slides and start slideshow
function goSlides(t, x){
	//set timer and animation variables
	time = t;
	xfade = x;
	
	//find the # of slides
	var allSlides = document.getElementById('slides').getElementsByTagName('div');
		
	//for loop to retrieve all of the slides
	for (var i=0; i<allSlides.length; i++) {
		var num = i.toString();
		var name = "s" + num;
		
		//add slides to the end of the array
		slides[slides.length] = document.getElementById(name).innerHTML.toString();
	};
	
	//place first slide into HTML page
	document.getElementById('slideshow').innerHTML=slides[0];
	
	//timer to switch to next slide
	o = window.setTimeout(nextSlide,t*1000);
};

//*****************************************************************

//fade out current slide
function nextSlide(){
	$(document.getElementById('slideshow')).animate({	
		opacity:'toggle'
	},xfade*1000);	
	o = window.setTimeout(switchSlide,xfade*1000);
};

//fade in new slide
function switchSlide(){
	current++;
	if(current==slides.length){current=0};
	document.getElementById('slideshow').innerHTML=slides[current];
	$(document.getElementById('slideshow')).animate({	
		opacity:'toggle'
	},xfade*1000);
	
	//repeat
	o = window.setTimeout(nextSlide,(time+xfade)*1000);
};

//*****************************************************************

//change out slide via manual click of BACK or NEXT button
function changeSlide(a){
	//stop current timer and animation
	clearTimeout(o);
	$(document.getElementById('slideshow')).stop();
	
	//if a is true, increase variable, else decrease
	a==true ? current++ : current--;
	if(current==slides.length){current=0};
	if(current<0){current=slides.length-1};
	
	//set new slide and set opacity to 100%
	document.getElementById('slideshow').innerHTML=slides[current];
	document.getElementById('slideshow').style.opacity=1.0;
	document.getElementById('slideshow').style.filter='alpha(opacity=100)';
	
	//restart timer
	o = window.setTimeout(nextSlide,(time)*1000);
};

