var interval = 5; // delay between rotating images (in seconds)
var random_display = 0; // 0 = no, 1 = yes
interval *= 1000;
var thePlace;
var alertID;
var isPaused = 0;


var image_index = 0;
image_list = new Array();
var headline_index=0;
headline_list=new Array();
var link_index=0;
link_list=new Array();


headline_list[headline_index++]='Grove Park Visits Science Center';
image_list[image_index++] = new imageItem("/images/headlines/2011-2012/gp_science.jpg");
link_list[link_index++]='http://web.dps.k12.va.us/Schools/Grove%20Park/Events%20&%20Activities/2011-2012/Burton/DanvilleScienceCenter.html';

headline_list[headline_index++]='Gibson Class Showered with Supplies';
image_list[image_index++] = new imageItem("/images/headlines/2011-2012/gb_grant.jpg");
link_list[link_index++]='http://web.dps.k12.va.us/Schools/Gibson/Events/2011-2012/DonorsChoose.html';

headline_list[headline_index++]='Westwood\'s Spelling Bee';
image_list[image_index++] = new imageItem("/images/headlines/2011-2012/ws_spelling.jpg");
link_list[link_index++]='http://web.dps.k12.va.us/Schools/Westwood/Events/SpellingBee.html';

headline_list[headline_index++]='Johnson\'s Aspiring Young Ladies';
image_list[image_index++] = new imageItem("/images/headlines/2011-2012/jo_aspiring.jpg");
link_list[link_index++]='http://web.dps.k12.va.us/Schools/Johnson/Events/2011-2012/aspiringYoungLadies.html';







var number_of_image = image_list.length;


function imageItem(image_location) {
this.image_item = new Image();
this.image_item.src = image_location;
}

function get_ImageItemLocation(imageObj) {
return(imageObj.image_item.src)
}

function generate(x, y) {
var range = y - x + 1;
return Math.floor(Math.random() * range) + x;
}

function getNextImage() {
if (random_display) {
image_index = generate(0, number_of_image-1);
headline_index=image_index;
link_index=image_index;
}

else {
image_index = (image_index+1) % number_of_image;
headline_index=image_index;
link_index=image_index;
}

var new_image = get_ImageItemLocation(image_list[image_index]);
return(new_image);

}

function rotatePause(){
	/*if(isPaused){
		isPaused=0;
		clearTimeout(alertID);
		rotateImage(thePlace);}
	else{
		isPaused=1;*/
		clearTimeout(alertID);/*}*/
}


function rotateNext(){
	clearTimeout(alertID);
	rotateImage(thePlace);
	}
	
function rotateBack(){}


function rotateImage(place) {
	thePlace=place;
	var new_image = getNextImage();
	document[place].src = new_image;
	var recur_call = "rotateImage('"+place+"')";
	alertID=setTimeout(recur_call, interval);
	document.getElementById('currenttext').innerHTML = '<table><tr><td><p><a href=\"' + link_list[link_index] + '\">' + headline_list[headline_index] + '</a></p></td></tr></table></p>';

}
