// Image Swap Stuff

var pics = new Array();

pics[0] = "images/quadShot5.jpg";
pics[1] = "images/state2009.jpg";
pics[2] = "images/lawn2009.jpg";
pics[3] = "images/class2009.jpg";
//pics[4] = "images/filmStrip05.jpg";
//pics[5] = "photos2008/state-podium.jpg";
//pics[6] = "images/quadShot5.jpg";

var headlines = new Array();
headlines[0] = "Discover more. Enrich your Experience.";
headlines[1] = "India as an Emerging Great Power";
headlines[2] = "Semester Program: Sciences Po";
//headlines[3] = "Dual Degree Program: Japan";
//headlines[4] = "Integrating Europe in a Changing World";
//headlines[5] = "Dual Degree Program: Costa Rica";
//headlines[6] = "Semester Program: American University in Cairo"; 

var newsTexts = new Array();
newsTexts[0] = "Enrich your undergraduate or graduate experience by enrolling in our dual degree or study abroad programs.";
newsTexts[1] = "Get a rare glimpse into the politics, policies, and people of India in our summer study abroad program to India.";
newsTexts[2] = "Study international relations in the heart of Paris.";
newsTexts[3] = "Earn Master's degrees in international affairs at American University and Ritsumeikan University in Kyoto.";
//newsTexts[4] = "Debate and discuss matters vital to European integration with the best international minds in our summer study abroad program to Italy.";
//newsTexts[5] = "Earn Master's degrees in Natural Resources and Sustainable Development at American University and the University for Peace in San Jose.";
//newsTexts[6] = "Study international relations at the Middle East's premier English language institution.";

var newsLinks = new Array();
newsLinks[0] = "http://www.american.edu/sis/sisabroad/summer/southafrica.html";
newsLinks[1] = "http://www.american.edu/sis/sisabroad/summer/india.html";
newsLinks[2] = "http://www.american.edu/sis/sisabroad/summer/italy.html";
newsLinks[3] = "http://www.american.edu/sis/sisabroad/gdualdegree/ru.html";
//newsLinks[4] = "http://www.american.edu/sis/academics/graduateprograms/ddp/nrsd.htm";
//newsLinks[5] = "index.html";
//newsLinks[6] = "index.html";
var secondsBetween = 10; // seconds between changing pictures
var secondsForFade = 10; // seconds of duration of fade
var seconds2start = 5; // time in seconds to wait for first image change. Starts after all images load

//END OF VARIABLES TO EDIT

var numberPictures = pics.length;
var lastPic = numberPictures - 1;
var firstWait = seconds2start * 1000;
var wait = secondsBetween * 1000;



// Cache images
//global object
var isf = { 'clock' : null, 'fade' : true, 'count' : 1 }

isf.imgs = [

];

var picCount = 0;

var counter = 1;
var swapCode = "";

function loadImages(){
for(var i = 0; i < numberPictures; i++){
	isf.imgs[i] = new Image();
	isf.imgs[i].onload = countImages;	
	isf.imgs[i].src = pics[i];
}

function countImages(){
	picCount++;
	if (picCount >= numberPictures){
		setTimeout("cyclePics()", firstWait)
		//cyclePics();
	}
}
}

function cyclePics(){
	//swapCode = "<dl><dt>" + headlines[counter] + "</dt><dd>" + newsTexts[counter] + "</dd></dl>";
	swapfade(document.getElementById('pic'), pics[counter], secondsForFade);
	counter++;
	if (counter > lastPic){counter = 0};	
	setTimeout("cyclePics()", wait);
}


//cache the images
//isf.imgsLen = isf.imgs.length;
//isf.cache = [];
//for(var i=0; i<isf.imgsLen; i++)
//{
//	isf.cache[i] = new Image;
//	isf.cache[i].src = isf.imgs[i];
//}	
	
//swapfade setup function
function swapfade()
{
	//if the timer is not already going
	if(isf.clock == null)
	{
		//copy the image object 
		isf.obj = arguments[0];
		
		//copy the image src argument 
		isf.src = arguments[1];
		
		//store the supported form of opacity
		if(typeof isf.obj.style.opacity != 'undefined')
		{
			isf.type = 'w3c';
		}
		else if(typeof isf.obj.style.MozOpacity != 'undefined')
		{
			isf.type = 'moz';
		}
		else if(typeof isf.obj.style.KhtmlOpacity != 'undefined')
		{
			isf.type = 'khtml';
		}
		else if(typeof isf.obj.filters == 'object')
		{
			//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
			//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
			//then the returned value type, which should be a number, but in mac/ie5 is an empty string
			isf.type = (isf.obj.filters.length > 0 && typeof isf.obj.filters.alpha == 'object' && typeof isf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
		}
		else
		{
			isf.type = 'none';
		}
		
		//change the image alt text if defined
		if(typeof arguments[3] != 'undefined' && arguments[3] != '')
		{
			isf.obj.alt = arguments[3];
		}
		
		//if any kind of opacity is supported
		if(isf.type != 'none')
		{
			//copy and convert fade duration argument 
			//the duration specifies the whole transition
			//but the swapfade is two distinct transitions
			isf.length = parseInt(arguments[2], 10) * 500;
			
			//create fade resolution argument as 20 steps per transition
			//again, split for the two distrinct transitions
			isf.resolution = parseInt(arguments[2], 10) * 10;
			
			//start the timer
			isf.clock = setInterval('isf.swapfade()', isf.length/isf.resolution);
		}
		
		//otherwise if opacity is not supported
		else
		{
			//just do the image swap
			isf.obj.src = isf.src;
			//swap the text at right
		//if (document.all){
		//document.all.story.innerHTML = swapCode;	
		//} else {
		//document.getElementById('story').innerHTML = swapCode;
		//}	
		}
		
	}
};


//swapfade timer function
isf.swapfade = function()
{
	//increase or reduce the counter on an exponential scale
	isf.count = (isf.fade) ? isf.count * 0.9 : (isf.count * (1/0.9)); 
	

	
	//if the counter has reached the bottom
	if(isf.count < (1 / isf.resolution))
	{
		//clear the timer
		clearInterval(isf.clock);
		isf.clock = null;

		//do the image swap
		isf.obj.src = isf.src;
		//swap the text at right
		//if (document.all){
		//document.all.story.innerHTML = swapCode;	
		//} else {
		//document.getElementById('story').innerHTML = swapCode;
		//}	
		//reverse the fade direction flag
		isf.fade = false;
		
		//restart the timer
		isf.clock = setInterval('isf.swapfade()', isf.length/isf.resolution);

	}
	
	//if the counter has reached the top
	if(isf.count > (1 - (1 / isf.resolution)))
	{
		//clear the timer
		clearInterval(isf.clock);
		isf.clock = null;

		//reset the fade direction flag
		isf.fade = true;
		
		//reset the counter
		isf.count = 1;
	}

	//set new opacity value on element
	//using whatever method is supported
	switch(isf.type)
	{
		case 'ie' :
			isf.obj.filters.alpha.opacity = isf.count * 100;
			break;
			
		case 'khtml' :
			isf.obj.style.KhtmlOpacity = isf.count;
			break;
			
		case 'moz' : 
			//restrict max opacity to prevent a visual popping effect in firefox
			isf.obj.style.MozOpacity = (isf.count == 1 ? 0.9999999 : isf.count);
			break;
			
		default : 
			//restrict max opacity to prevent a visual popping effect in firefox
			isf.obj.style.opacity = (isf.count == 1 ? 0.9999999 : isf.count);
	}
};