var photos = new Array();
photos[0] = "slide1_7.jpg|A Coldwar Timeline|/coldwar/timeline.php";
photos[1] = "slide2_7.jpg|The Art of Listening|/video/highlights.php?type=listening";
photos[2] = "slide3_7.jpg|Video Showcase|/video/index.php";
photos[3] = "slide4_7.jpg|Who Is George Shultz|shultz/index.php";

var photoPos =new Array();
photoPos[0] = 20;
photoPos[1] = 120;
photoPos[2] = 220;
photoPos[3] = 320;
photoPos[4] = 320;

var TIMER = 5000, FADESPEED = 50, position = 0, GtimerId;
var timeOutFlag;
var normalBK="#000000", currentBK="#b49e4d";
var slideRunning=1;

function initSlideShow() {
	setOpacity(document.getElementById("topImage"), 1.0);
	document.getElementById("topImage").style.zIndex = 51;
	var img = new Image();
	img.onload = setPhoto;
	if (photos[position].indexOf("|") != -1) { 
		img.alt = photos[position].split("|")[1];
		img.src = "images/" + photos[position].split("|")[0];
	} else {
		img.src = "images/" + photos[position];
	}
	createNavigation();
	setBkColor(position+1);
}

function createNavigation() {
	var obj = document.getElementById("slideshowNav");
	if(obj != null){
		for(i=1;i<(photos.length+1);++i){			
			var img = document.createElement("a");
			img.setAttribute("href","javascript:jumpPhoto("+(i-1)+")");
			img.setAttribute("id","pic"+i);
			var txt =document.createTextNode(""+i);
			var blk =document.createTextNode(" ");
			img.appendChild(txt);
			obj.appendChild(img);
			obj.appendChild(blk);
		}
	}
}

function setPhoto() {
	var obj = document.getElementById("topImage");
	if(obj != null) document.getElementById("slideshow").removeChild(obj);
	var img = document.createElement("img");
	img.setAttribute("src",this.src);
	img.setAttribute("id","topImage");
	img.setAttribute("height",this.height);
	img.setAttribute("width",this.width);
	img.setAttribute("border","0");
	setOpacity(img, 1.0);
	document.getElementById("slideshow").appendChild(img);
	if (this.alt) { 
		img.setAttribute("alt",this.alt);
	} else {
		img.setAttribute("alt","Turmoil and Triumph");
	}
	document.getElementById("topImage").style.zIndex = 51;
	if (slideRunning == 1) {
		loadPhoto();
	}
}

function loadPhoto() {
	if (position == (photos.length - 1)) { position = 0; }
	else { position++; }
	var img = new Image();
	img.onload = loadUnder;
	if (photos[position].indexOf("|") != -1) { 
		img.alt = photos[position].split("|")[1];
		img.src = "images/" + photos[position].split("|")[0];
	} else {
		img.src = "images/" + photos[position];
	}
	slideRunning=1;
}

function loadUnder() {
	var img = document.createElement("img");
	img.setAttribute("src",this.src);
	img.setAttribute("id","bottomImage");
	img.setAttribute("height",this.height);
	img.setAttribute("width",this.width);
	img.setAttribute("border","0");
	setOpacity(img, 1.0);
	document.getElementById("slideshow").appendChild(img);
	if (this.alt) { 
		//addPhotoText(this.alt);
		img.setAttribute("alt",this.alt);
	}
	else { img.setAttribute("alt","US Department of Justice Slide Show image"); }
	timeOutFlag=setTimeout("initFade()",TIMER);
}

function addPhotoText(text) {
	var div = document.createElement("div");
	div.setAttribute("id","bottomTextOverlay");
	setOpacity(div, 0.8);
	var span = document.createElement("span");
	span.appendChild(document.createTextNode(text));
	div.appendChild(span);
	document.getElementById("slideshow").appendChild(div);
}

function initFade() {
	GtimerId = setInterval("fadeOut()",FADESPEED);
	document.getElementById("topImage").style.zIndex = 51;
	if (document.getElementById("topTextOverlay") != null)
		document.getElementById("slideshow").removeChild(document.getElementById("topTextOverlay"));
	if (document.getElementById("bottomTextOverlay") != null)
		document.getElementById("bottomTextOverlay").setAttribute("id","topTextOverlay");
}

function fadeOut() {
	var obj = document.getElementById("topImage");
	if (obj.style.opacity < 0.1) {
		clearInterval(GtimerId);
		document.getElementById("slideshow").removeChild(obj);
		document.getElementById("bottomImage").setAttribute("id","topImage");
		setBkColor(position+1);
		loadPhoto();
	}
	else { setOpacity(obj, (obj.style.opacity - 0.1)); }
}

function setOpacity(obj, opacity) {
	obj.style.opacity = opacity;
	obj.style.MozOpacity = opacity;
	obj.style.KhtmlOpacity = opacity;
	obj.style.filter = "alpha(opacity=" + (opacity * 100) + ")";
}

function jumpPhoto(noPic) {
	position=noPic;
	if (position == photos.length) {
		position = 0;
	}
	var img = new Image();
	img.onload = loadJump;
	if (photos[position].indexOf("|") != -1) { 
		img.alt = photos[position].split("|")[1];
		img.src = "images/" + photos[position].split("|")[0];
	} else {
		img.src = "images/"+ photos[position];
	}
	slideRunning=0;
}

function loadJump() {
	var obj = document.getElementById("bottomImage");
	if(obj != null) document.getElementById("slideshow").removeChild(obj);
	var img = document.createElement("img");
	img.setAttribute("src",this.src);
	img.setAttribute("id","bottomImage");
	img.setAttribute("height",this.height);
	img.setAttribute("width",this.width);
	img.setAttribute("border","0");
	setOpacity(img, 1.0);
	document.getElementById("slideshow").appendChild(img);
	if (this.alt) { 
		img.setAttribute("alt",this.alt);
	} else {
		img.setAttribute("alt","Turmoil and Triumph");
	}
	setBkColor(position+1);
	clearTimeout(timeOutFlag);
	clearInterval(GtimerId);
	GtimerId = setInterval("jumpFadeOut()",FADESPEED/3);
	document.getElementById("topImage").style.zIndex = 51;
}

function jumpFadeOut() {
	var obj = document.getElementById("topImage");
	if (obj.style.opacity < 0.1) {
		clearInterval(GtimerId);
		document.getElementById("slideshow").removeChild(obj);
		document.getElementById("bottomImage").setAttribute("id","topImage");
	} else {
		setOpacity(obj, (obj.style.opacity - 0.1));
	}
}

//The script for the rotating links starts here.
function slidelink(){
	var current=position;
	if (slideRunning == 1) {
	   var current=(position!=0?position-1:(photos.length - 1));
	}
	window.location=photos[current].split("|")[2];
}

function setBkColor(item){
	try {	
		for(i=1;i<(photos.length+1);++i) {
			document.getElementById("pic"+i).style.backgroundColor=normalBK;
		}
	} catch(err) {
	
	}
	try {
		document.getElementById("pic"+item).style.backgroundColor=currentBK;
	} catch(err) {
	
	}
}

