var run_slideshow = 1;
var next_image;
var myTimer;
var timeInterval = 5000;

var createdList = false;
function updateSlide(current_image) {
	if(run_slideshow == 1) {
		
    //find out what next image number will be
		if(!document.getElementById('slideshow_images_' + current_image)) { 
			var tmp = 0;
			while(document.getElementById('slideshow_image_link_' + tmp)) {
				tmp++;
			}
			current_image = parseInt(tmp)-parseInt(1); 
			next_image = 0;
		} else {		
			next_image = current_image + 1;
		}
		
		if(!document.getElementById('slideshow_images_' + next_image)) { 
			next_image = 0; 
		}
		
    //fade out all images if they are showing
		/* tmp = 0;
		while(document.getElementById('slideshow_image_link_' + tmp)) {
			document.getElementById('slideshow_image_link_' + tmp).className = '';
			if(tmp != next_image) {
				Effect.Fade("slideshow_images_" + tmp, { duration:1});
			}
			tmp++;
		}
		
    //change link class names
		if (document.getElementById('slideshow_image_link_' + current_image)) {
			document.getElementById('slideshow_image_link_' + current_image).className = '';
		}
		if (document.getElementById('slideshow_image_link_' + next_image)) {
			document.getElementById('slideshow_image_link_' + next_image).className = 'active';
		}*/
    
    //fade out currently displayed image
		if (document.getElementById('slideshow_images_' + current_image)) {
			Effect.Fade("slideshow_images_" + current_image, {
				duration: 1
			});
		}
    
		if (document.getElementById('slideshow_images_' + next_image)) {
			Effect.Appear("slideshow_images_" + next_image, {
				duration: 1
			});
		}
    
    //setup timer so next image will show in 5 seconds
    clearTimeout(myTimer);
		if (document.getElementById('slideshow_images_' + next_image)) {
			setTimeout("Effect.Appear('slideshow_images_" + next_image + "', { duration:1});", 1000);
      myTimer = setTimeout("updateSlide(" + next_image + ")", timeInterval);
		}
	}	
}

function showSlide(current_image) {
	if(run_slideshow == 0) {
		run_slideshow = 1;
	}
	current_image = parseInt(current_image)-parseInt(1);
	if(current_image < 0) {
		var tmp = 0;
		while(document.getElementById('slideshow_images_' + tmp)) {
			tmp++;
		}
		current_image =  parseInt(tmp)+parseInt(1);
	}
  
	updateSlide(current_image);
}

function stopSlideshow() {
	if(run_slideshow == 1) {
		run_slideshow = 0;
		document.getElementById('slideshow_control').className = 'slideshow_play';
	} else {
    run_slideshow = 1;
		document.getElementById('slideshow_control').className = 'slideshow_pause';
	}
	document.getElementById('slideshow_control').blur();
	updateSlide(next_image);
}