// script to rotate images and links.
// copyright (C) 2005-2008 by Christ Presbyterian Church, All rights reserved
// last modified Apr. 31, 2008
// modified Mar. 31 to add page for this week gcp
// modified Apr 24 to add cpc cafe and delete kiterunner
// modified May 16 to add labyrinth and take out cpc cafe
// modified June 26 06 to put in new mission picture
// modified Feb 19 07 to make this week second 
// modified Feb 22 07 to make this week non rotate and add sec sun rotate
// modified Dec 10 07 to take out second sunday
// modified Apr. 31 08 to add one link since link to covenant was put in
// modified Apr. 09 to take out one link
// modified Apr. 30 09 to put in another link since greenfaith was added

// modified Apr. 17 09 to take out the one link to covenant
var stop = 0; // flag which stops rotation, 0=rotate, 1=stop, set in html cod
var maxrecursions = 1500; // max number rotations
var recursions = 0; // counter to count rotations
var loop = 0; //image counter to indicate current image, starts at 0
var img=new Array(); // array of images
var number_of_pictures=3; // the number of pictures we want to rotate
for (i=0;i<number_of_pictures;i++){
 img[i]=new Image();
}

// the image array
img[0].src="fellowshipsmall.jpg"; // first image
img[1].src="labyrinthr.jpg";
img[2].src="kwomanworkingsmall.jpg";

// the corresponding links
var mlinks = new Array(); 
mlinks[0] = "fellowship2.html";// first link
mlinks[1] = "labyrinth2.html"; 
mlinks[2] = "mission2.html";

// this function will do the rotating
function updateImg() {

	// first check to see if we should change the image
	if(stop==0) {
		loop++; // update the image index
      	 	if (loop == number_of_pictures) {
			loop=0; }// its greater than number of images so reset
		document.theimage.src=img[loop].src; // reset the image source
		// change the href for the 12th link, links start at 0
                // pictures are links also
		document.links[12].href=mlinks[loop];
	} // end stop==0

        // check on max recursions if more than maxrecursions don't recurse
        if ( recursions <= maxrecursions) {
	recursions++; // up the recursion count
       	setTimeout("updateImg();",3000); // loop after 3 seconds
	} // end recursion check
} 


