// JavaScript Document



// slideshow options

var start_num = 1; 			// slide to start slideshow with
var fade_speed = 2; 		// speed of the fade transition. value between 1 and 5, 1 being fastest.
var hide_text = false; 		// when true, text hides between fade in and out of images
var slideshow_start = 6; 	// pause, in seconds, before beginning the slideshow after page has loaded
var slideshow_speed = 6; 	// how long, in seconds, before the slide changes
var slideshow_pause = 12; 	// pause, in seconds, after a thumbnail is clicked


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

var slideshow_content = [
['1',
'In 1993...',
'ccc',
'The UN passed a resolution which said... <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &ldquo;States should condemn <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; violence against women&rdquo;'
],

['2',
'In 2008...',
'ccc',
'UNIFEM began a public campaign to <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lsquo;inspire&rsquo; the member states <br/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to act by 2015'
],

['3',
'MEANWHILE',
'ccc',
'Over the next year...'
],


['4',
'In India',
'ccc',
'A bride burning occurs every two hours'
],

['5',
'and Canada',
'ccc',
'1 woman in 6 is physically or sexually abused by her partner'
],

['6',
'Et Cameroon',
'ccc',
'20 pour cent des femmes sont victimes de mutilations g&eacute;nitales f&eacute;minines'
],

['7',
'E Brazil...',
'ccc',
'Mais da metade das mulheres n &atilde; o procuram ajuda quando est &atilde; o a sofrendo viol &ecirc;ncia f&igrave;sica por parte do companheiro'
],

['8',
'Y M&eacute;xico...',
'ccc',
'Cerca de 5,000 ni&ntilde;os/as est&aacute;n involucrados en prostituci&#243;n, pornograf&iacute; a y turismo sexual'
],

['9',
'Five more years',
'ccc',
'While women continue to be abused <br/>and victimized'
],

['10',
'WHAT DOES IT TAKE',
'ccc',
'to bring this to an end NOW?'
],


['11',
'It takes',
'ccc',
'a global movement of people who care'
],

['12',
 'People like us to say loud and clear',
'ccc',
'YES, OUI, JA, SI, SIM, ANO, TAK, IGEN, HO, BALEH, NA&#39;AM, KEN, AWO, A-YO,  KEN, Oo, DA, NAI, HUFI, NDIYO'
],

['13',
'YES TO THE CAMPAIGN...',
'ccc',
'A SAFE WORLD FOR WOMEN'
]

];


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 = "img/slideshow/"+slideshow_content[i][0]+".jpg";
	}
}








var start_timer;
var auto_timer;
var auto_slide;

function start_slideshow() {
	thumbs_on(start_num);
	document.getElementById('slideshow_image').src = "img/slideshow/"+slideshow_content[start_num-1][0]+".jpg";
	document.getElementById('div_slideshow_header').innerHTML = slideshow_content[start_num-1][1];
	document.getElementById('div_slideshow_thumbs_header').style.color = "#"+slideshow_content[start_num-1][2];
	document.getElementById('div_slideshow_text').innerHTML = slideshow_content[start_num-1][3];
	if (start_num < slideshow_amount) {
		auto_slide = start_num+1;
	} else {
		auto_slide = 1;
	}
	start_timer = setTimeout("run_slideshow()",slideshow_start*1000);
}

var click_pause;

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 text_pause;
var in_fade = false;

function change_slideshow(slide_num,auto) {
	
	// reset timer
	clearTimeout(start_timer);
	clearTimeout(timer);
	clearTimeout(auto_timer);
	clearTimeout(click_pause);
	clearTimeout(text_pause);
	
	// 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 = "img/slideshow/"+slideshow_content[slide_num-1][0]+".jpg";
	// 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;
	
	// delete text
	if (hide_text) {
	document.getElementById('div_slideshow_header').innerHTML = "";
	document.getElementById('div_slideshow_text').innerHTML = "";
	} else {
		swap_text();
	}

	// turn thumb on
	thumbs_on(slide_num);

	// if clicked
		if (!auto) {
		thumbs_on(slide_num);
		// uncomment below if you want the slideshow to start after the one clicked. 
		// if not, it starts where it left off
		//auto_slide = slide_num+1;
		if (slide_num == auto_slide) {
			if (auto_slide < slideshow_amount) {
			auto_slide++;
			} else {
			auto_slide = 1;
			}
		}
		//alert(auto_slide);
		click_pause = setTimeout("run_slideshow()",slideshow_pause*1000);
		}
}
function swap_text(slide_num) {
	document.getElementById('div_slideshow_header').innerHTML = slideshow_content[current_num-1][1];
	//change header color
	document.getElementById('div_slideshow_thumbs_header').style.color = "#"+slideshow_content[current_num-1][2];
	document.getElementById('div_slideshow_text').innerHTML = slideshow_content[current_num-1][3];
	clearTimeout(text_pause);
}

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*30;
	// put pause in fade and make loop
	timer = setTimeout("fade_image()",fade_pause);
	
	// increment opacity down
	image_opacity = image_opacity-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 = "img/slideshow/"+slideshow_content[current_num-1][0]+".jpg";
	document.getElementById('slideshow_image_under').style.opacity = 0;

	// get text
	if (hide_text) {
	swap_text();
	}

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



function thumbs_on(slide_num) {
	for (i=1;i<=slideshow_amount;i++) {
	thumb_name = "slideshow_thumb"+i;
	//alert(thumb_name);
	el = document.getElementById(thumb_name);
	
	document.getElementById(thumb_name).style.margin = "0px 1px 1px 0px";
	document.getElementById(thumb_name).style.border = "0";
	}
	thumb_on_name = 'slideshow_thumb'+slide_num;
	document.getElementById(thumb_on_name).style.margin = "-1px 1px 1px 0px";
	document.getElementById(thumb_on_name).style.border = "0";
}
















///////////////////////
/*
var top_slide = 4;
var bottom_slide;


function do_fade(img_num) {
	opacity_in = 0;
	opacity_out = 100;

	clearTimeout(in_timer);
	clearTimeout(out_timer);

	top_slide = slideshow_content[top_slide-1][0];
	bottom_slide = slideshow_content[img_num-1][0];

	document.getElementById('slideshow_image_under').style.opacity = 0;
	document.getElementById('slideshow_image_under').src = "img/slideshow/"+bottom_slide+".jpg";

	fade_in();
	fade_out();
}


var opacity_in = 0;
var in_timer;
var opacity_out = 100;
var out_timer;


function fade_in() {

	if (opacity_in < 100) {
	document.getElementById('slideshow_image_under').style.opacity = opacity_in/100;
	}
	
	in_timer = setTimeout("fade_in()",10);
	
	opacity_in++;

	if (opacity_in == 100) {
	document.getElementById('slideshow_image').src = "img/slideshow/"+bottom_slide+".jpg";
	document.getElementById('slideshow_image').style.opacity = 1;
	}
}


function fade_out() {
	if (opacity_in > 0) {
	document.getElementById('slideshow_image').style.opacity = opacity_out/100;
	}
	
	out_timer = setTimeout("fade_out()",10);
	
	opacity_out--;

}
	
*/
///////////////////////





