
// If you change the first image, you need to change the initial image on justice.gov home page.
var photos = new Array();
photos[0] = "holder-testify.jpg|Attorney General Eric Holder Testifies Before the Senate Judiciary Committee|http://www.justice.gov/ag/testimony/2009/ag-testimony-091118.html";
photos[1] = "interagency-seals.jpg|President Obama Establishes Interagency Financial Fraud Enforcement Task Force|/opa/pr/2009/November/09-opa-1243.html";
photos[2] = "doj-dod-detainees.jpg|Departments of Justice and Defense Announce Forum Decisions for 10 Guantanamo Bay Detainees|/ag/speeches/2009/ag-speech-091113.html";
photos[3] = "vawa-15.jpg|Commemorating 15 Years of the Violence Against Women Act|http://www.ovw.usdoj.gov/vawa15.htm";
photos[4] = "enrd-100.jpg|The 100th Anniversary of the Environment and Natural Resources Division|http://www.justice.gov/enrd/Anniversary/index.html";
var photoPos =new Array();
photoPos[0] = 20;
photoPos[1] = 120;
photoPos[2] = 220;
photoPos[3] = 320;
photoPos[4] = 320;
 



// The base link should be set relative to the page the slideshow appears on.
var BASELINK = "/slideshow/";

// There should be no need to alter anything below this line.
var TIMER = 6000, FADESPEED = 100, position = 0, GtimerId;
var timeOutFlag;
var normalBK="#999999", currentBK="#a6824b";
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 = BASELINK + photos[position].split("|")[0];
	}
	else { img.src = BASELINK + 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","US Department of Justice Slide Show image"); }
	
	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 = BASELINK + photos[position].split("|")[0];
	}
	else { img.src = BASELINK + 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 = BASELINK + photos[position].split("|")[0];
	}
	else { img.src = BASELINK + 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","US Department of Justice Slide Show image"); }
	
	
	//var obj1 = document.getElementById("topImage");
	//document.getElementById("slideshow").removeChild(obj1);
	//document.getElementById("bottomImage").setAttribute("id","topImage");

	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 showNavigation(){

	//var current=(position!=0?position-1:(photos.length - 1));
	//var obj = document.getElementById("slideshowNav");
	//obj.style.zIndex=55;
	//obj.style.top=photoPos[current];
}
 
function hideNavigation(){

	//var obj = document.getElementById("slideshowNav");
	//obj.style.zIndex=0;
	//obj.style.
}

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){
	
	}
}
// window.onload = setTimeout("initSlideShow()",1000);
