// JavaScript Document



// slideshow options

var start_num = 1; 			// slide to start slideshow with
var fade_speed = 1; 		// speed of the fade transition. value between 1 and 5, 1 being fastest.
var slideshow_start = 4; 	// pause, in seconds, before beginning the slideshow after page has loaded
var slideshow_speed = 5; 	// how long, in seconds, before the slide changes


// slide show content: Image/Slide Number, Title, Header Color (UNIFEM'S WORK), Text



var slideshow_amount = slideshow_content.length;

// preload slideshow images
function preload_slideshow_images() {
	for (i=0;i<slideshow_amount;i++) {
	slide_image = new Image();
	slide_image.src = slideshow_dir+slideshow_content[i][0]+"/"+slideshow_content[i][1]+"."+slideshow_content[i][2];
	}
}








var start_timer;
var auto_timer;
var auto_slide;

function start_slideshow() {
	document.getElementById('slideshow_image').src = slideshow_dir+slideshow_content[start_num-1][0]+"/"+slideshow_content[start_num-1][1]+"."+slideshow_content[start_num-1][2];
	if (start_num < slideshow_amount) {
		auto_slide = start_num+1;
	} else {
		auto_slide = 1;
	}
	start_timer = setTimeout("run_slideshow()",slideshow_start*1000);
}


function run_slideshow() {

	change_slideshow(auto_slide,true);

	auto_timer = setTimeout("run_slideshow()",slideshow_speed*1000);

	if (auto_slide < slideshow_amount) {
	auto_slide++;
	} else {
	auto_slide = 1;
	}
}





var current_num;
var image_opacity = 100;
var timer;
var in_fade = false;

function change_slideshow(slide_num,auto) {
	// reset timer
	clearTimeout(start_timer);
	clearTimeout(timer);
	clearTimeout(auto_timer);
	
	// set opacity variable to 100
	image_opacity = 100;
	
	// set top slideshow image opacity to 100%
	document.getElementById('slideshow_image').style.opacity = 1;
	document.getElementById('slideshow_image').style.filter = "alpha(opacity=100)";

	// insert new slideshow image into bottom space
	document.getElementById('slideshow_image_under').src = slideshow_dir+slideshow_content[slide_num-1][0]+"/"+slideshow_content[slide_num-1][1]+"."+slideshow_content[slide_num-1][2];

	// change its opacity to 100%
	document.getElementById('slideshow_image_under').style.opacity = 1;
	document.getElementById('slideshow_image_under').style.filter = "alpha(opacity=100)";

	// activate fade
	fade_image();

	// set current slide variable
	current_num = slide_num;
	}

function fade_image() {

	// fade loop
	if (image_opacity > 0) {
	
	// set fade variable true
	in_fade = true;
	
	document.getElementById('slideshow_image').style.opacity = image_opacity/100;
	document.getElementById('slideshow_image').style.filter = "alpha(opacity="+image_opacity+")";
	}
	
	fade_pause = fade_speed*20;
	
	// put pause in fade and make loop
	timer = setTimeout("fade_image()",fade_pause);
	
	// increment opacity down
	image_opacity = image_opacity-2; //5


	// when opacity hits 0 set top image to 100% and bottom image to 0 so FF doesn't flicker
	if (image_opacity == 0) {
	document.getElementById('slideshow_image').style.opacity = 1;
	document.getElementById('slideshow_image').src = slideshow_dir+slideshow_content[current_num-1][0]+"/"+slideshow_content[current_num-1][1]+"."+slideshow_content[current_num-1][2];
	
	document.getElementById('slideshow_image_under').style.opacity = 0;

	// set fade variable false
	in_fade = false;
	}
}


