var interval = 4000;				//1000 is 1 second
var currentIndex = -1;
var autoStart = "on";		//automatically start? requires call to (call imageRotator())
var autoRotate = "off";		//initialize as "off".. dont change this.. 
var pictureId = "tour_pic";			//id of <IMG> to make into a slideshow
var descriptionId = "pic_description";		//id of <P> to change the id="sdesciption_id"
var started = false;
var totalSlides = 23;				//fake the status out by presetting the array size.. since it preloads in multiple pieces.. the array would otherwise be small.  and it would say "Image 1 of 2".. now it says "Image 1 of 18" even before all 18 images have been loaded
imagesArray = new Array(totalSlides);

//  ---------------------------------------------------------------------------------------
// |  Preloading one image so page can load, otherwise, 
// |   you must wait till all pics preload b4 you see the page at all
//  ---------------------------------------------------------------------------------------

image0 = new Image();
image0.src = "http://184.154.234.11/~ci26/images/arroyo.jpg";
image0_description = "Equestrian Arena <br />Playground <br />2 Baseball/Softball Fields <br />1 Soccer/Multipurpose Field";
imagesArray[0] = new imageData(image0, "Arroyo Park<BR>20994 Yorba Linda Blvd", image0_description);

function preLoadImages() {
	image1 = new Image();
	image1.src = "http://184.154.234.11/~ci26/images/boxcanyon.jpg";
	image1_description = "Playground";
	imagesArray[1] = new imageData(image1, "Box Canyon Park<BR>22400 Foxtail", image1_description);

	image2 = new Image();
	image2.src = "http://184.154.234.11/~ci26/images/brushcanyon.jpg";
	image2_description = "Par course <BR>Playground <BR>2 Baseball/Softball Fields <BR>1 Soccer/Multipurpose Field <BR>2 Tennis Courts (lighted) <BR>1 Basketball court (lighted)";
	imagesArray[2] = new imageData(image2, "Brush Canyon Park<BR>28282 Brush Canyon", image2_description);

	image3 = new Image();
	image3.src = "http://184.154.234.11/~ci26/images/bryantranch.jpg";
	image3_description = "2 Baseball Fields (lighted) <BR>1 Senior Baseball (lighted) <BR>1 Soccer/Multipurpose Field (lighted) <BR>Snack Stand";
	imagesArray[3] = new imageData(image3, "Bryant Ranch School<BR>24695 Paseo de Toronto", image3_description);

	image4 = new Image();
	image4.src = "http://184.154.234.11/~ci26/images/domingueztrailside.jpg";
	image4_description = "Horse Trail <BR>Open Space";
	imagesArray[4] = new imageData(image4, "Dominguez Trailside Park<BR>5600 Dominguez Ranch Road", image4_description);

	image5 = new Image();
	image5.src = "http://184.154.234.11/~ci26/images/eastside.jpg";
	image5_description = "2 Baseball/Softball Fields (lighted) <BR>1 Senior Baseball Field (lighted) <BR>2 Baseball/Softball Fields <BR>2 Soccer/Multipurpose Fields (lighted) Snack Stand";
	imagesArray[5] = new imageData(image5, "Eastside Community Park<BR>5400 Eastside Circle", image5_description);

	image6 = new Image();
	image6.src = "http://184.154.234.11/~ci26/images/fairmont.jpg";
	image6_description = "2 Tennis Courts (lighted) <BR>Open Space";
	imagesArray[6] = new imageData(image6, "Fairmont Knolls Park<BR>4700 Fairmont Blvd.", image6_description);

	image7 = new Image();
	image7.src = "http://184.154.234.11/~ci26/images/hurless.jpg";
	image7_description = "Group Picnic Areas <BR>2 Horseshoe Pits <BR>Playground <BR>Amphitheater (200 seating) <BR>Open Space";
	imagesArray[7] = new imageData(image7, "Hurless Barton Park<BR>4601 Casa Loma", image7_description);

	image8 = new Image();
	image8.src = "http://184.154.234.11/~ci26/images/jeanwoodard.jpg";
	image8_description = "Open Space <BR>Playground <BR>2 Baseball Fields <BR>1 Soccer/Multipurpose Field";
	imagesArray[8] = new imageData(image8, "Jean Woodard Park<BR>5451 Eastside Circle", image8_description);

	image9 = new Image();
	image9.src = "http://184.154.234.11/~ci26/images/jessamyn.jpg";
	image9_description = "Group Picnic Area <BR>1 Baseball/Softball Field <BR>1 1/2 Basketball Courts (lighted) <BR>1 Sand Volleyball Court (lighted)";
	imagesArray[9] = new imageData(image9, "Jessamyn West Park<BR>19115 Yorba Linda Blvd.", image9_description);

	image10 = new Image();
	image10.src = "http://184.154.234.11/~ci26/images/kingsbriar.jpg";
	image10_description = "Playground <BR>Open Space";
	imagesArray[10] = new imageData(image10, "Kingsbriar Park<BR>5560 Kingsbriar Drive", image10_description);

	image11 = new Image();
	image11.src = "http://184.154.234.11/~ci26/images/laspalomas.jpg";
	image11_description = "3 Tennis Courts (lighted) <BR>Open Space";
	imagesArray[11] = new imageData(image11, "Las Palomas Tennis Park<BR>20550 Paseo de las Palomas", image11_description);

	image12 = new Image();
	image12.src = "http://184.154.234.11/~ci26/images/buenavista.jpg";
	image12_description = "Equestrian Arena <BR>Warm-Up Arena <BR>Lunging Ring Restrooms";
	imagesArray[12] = new imageData(image12, "Phillip S. Paxton Equestrian Center<BR>(formerly the<BR>Buena Vista<BR>Equestrian Center)<BR>18661 Buena Vista", image12_description);

	image13 = new Image();
	image13.src = "http://184.154.234.11/~ci26/images/riodeloro.jpg";
	image13_description = "Open Space <BR>Playground";
	imagesArray[13] = new imageData(image13, "Rio Del Oro<BR>4800 Rio del Oro", image13_description);

	image14 = new Image();
	image14.src = "http://184.154.234.11/~ci26/images/rolandbigonger.jpg";
	image14_description = "Open Space <BR>Playground";
	imagesArray[14] = new imageData(image14, "Roland Bigonger Park<BR>19500 Parkside Drive", image14_description);

	image15 = new Image();
	image15.src = "http://184.154.234.11/~ci26/images/sanantonio.jpg";
	image15_description = "Equestrian Arena <BR>1 Baseball/Softball Field <BR>1 Soccer/Multipurpose Field <BR>1 Grass Volleyball Court";
	imagesArray[15] = new imageData(image15, "San Antonio Park<BR>4205 San Antonio", image15_description);

	image16 = new Image();
	image16.src = "http://184.154.234.11/~ci26/images/shapell.jpg";
	image16_description = "2 Baseball/Softball Fields <BR>1 Soccer/Multipurpose Field <BR>Open Space";
	imagesArray[16] = new imageData(image16, "Shapell Park<BR>5510 Vista Del Mar", image16_description);

	image17 = new Image();
	image17.src = "http://184.154.234.11/~ci26/images/thomaslasorda.jpg";
	image17_description = "22,500 sq. ft. Gymnasium <BR>2,500 sq. ft. Multipurpose Room";
	imagesArray[17] = new imageData(image17, "Thomas Lasorda, Jr. Field House<BR>4701 Casa Loma", image17_description);

	image18 = new Image();
	image18.src = "http://184.154.234.11/~ci26/images/travisranch.jpg";
	image18_description = "3 Baseball Fields <BR>1 Soccer/Multipurpose Field <BR>Snack Stand <BR>Playground";
	imagesArray[18] = new imageData(image18, "Travis Ranch Park<BR>21305 Via del Parque", image18_description);

	image19 = new Image();
	image19.src = "http://184.154.234.11/~ci26/images/travisranch_ac.jpg";
	image19_description = "7,350 sq. ft. Gymnasium <BR>2 Music rooms <BR>4 Meeting Rooms <BR>2 Combined Meeting Rooms <BR>Covered Patio";
	imagesArray[19] = new imageData(image19, "Travis Ranch Activity Center<BR>5200 Via de la Escuela", image19_description);

	image20 = new Image();
	image20.src = "http://184.154.234.11/~ci26/images/valleyview.jpg";
	image20_description = "Restrooms<BR>BBQ’s<BR>Playground Equipment for 2-5 year olds and 5-12 year olds<BR>Picnic Tables<BR>4 Lighted baseball fields (by permit)<BR>Lighted soccer/football field (by permit)<BR>Concession stand";
	imagesArray[20] = new imageData(image20, "Veterans Park<BR>4756 Valley View", image20_description);

	image21 = new Image();
	image21.src = "http://184.154.234.11/~ci26/images/vistadelverdepark.jpg";
	image21_description = "5 acres open turf area <BR>Soccer/Multipurpose Field (lighted) <BR>Group picnic area <BR>Barbecue grills <BR>Restrooms";
	imagesArray[21] = new imageData(image21, "Vista del Verde Park<BR>17600 Valley View", image21_description);

	image22 = new Image();
	image22.src = "http://184.154.234.11/~ci26/images/yorbalindacommunitycenter.jpg";
	image22_description = "Senior Citizens Center <BR>300-Seat Banquet Room <BR>200-Seat Banquet Room <BR>4 Meeting Rooms <BR>1 Multipurpose Room <BR>Full Service Commercial Kitchen";
	imagesArray[22] = new imageData(image22, "Yorba Linda Community Center<BR>4501 Casa Loma", image22_description);

	image23 = new Image();
	image23.src = "http://184.154.234.11/~ci26/images/yorbalindamiddleschool.jpg";
	image23_description = "2 Baseball/Softball Fields (lighted) <BR>1 Senior Baseball Field (lighted) <BR>2 Soccer/Multipurpose Fields (lighted) <BR>Snack Stand <BR>Walking Track";
	imagesArray[23] = new imageData(image23, "Yorba Linda Middle School<BR>4777 Casa Loma", image23_description);
}

function imageData (image, title, description) {
	this.image = image;
	this.title = title;
	this.description = description;
}

//  ------------------------------------------------------------
// | this should always be running.. call this once the page loads
//  ------------------------------------------------------------
function imageRotator() {

	//alert("imageRotater is called!" + interval);

	//initializes.  1) load the starting image, 2) start the slideshow
	if (started == false) {
		slideshowControl("first");
		preLoadImages();
		started = true;
		
		//if autostart is "on".. start the slideshow immediately
		if (autoStart == "on") {
			document.getElementById("status").innerHTML = "Playing..";
			setTimeout("slideshowControl('toggle')", interval);
		}
	}
	
	setTimeout("imageRotator()", interval);		
	rotateImage();
}

//  ------------------------------------------------------------
// | if (autoRotate == on) rotates the image once
//  ------------------------------------------------------------
function rotateImage() {

	if (autoRotate == "on")
	{
		if (++currentIndex >= imagesArray.length) {
			currentIndex = 0;
		}


		document.getElementById(pictureId).src = imagesArray[currentIndex].image.src;
		document.getElementById(pictureId).title = imagesArray[currentIndex].title;
		document.getElementById("title").innerHTML = imagesArray[currentIndex].title;
		document.getElementById("image_number").innerHTML = "Image " + (currentIndex + 1) + " of " + imagesArray.length;
		document.getElementById(descriptionId).innerHTML = imagesArray[currentIndex].description;
	}
}


//  ------------------------------------------------------------
// | Possible Actions:
// |
// | "first"	
// | "previous"
// | "toggle"
// | "next"
// | "last"
//  ------------------------------------------------------------
function slideshowControl(action) {

	//alert("Control called: " + action + ", autoRotate: " + autoRotate);

	if (action == "toggle") {
		if (autoRotate == "off") {
		
			//Show instant stauts update, dont wait till rotate image is called
			document.getElementById("status").innerHTML = "Playing..";
			autoRotate = "on"
		} else {

			//Show instant stauts update
			document.getElementById("status").innerHTML = "Paused";	
			autoRotate = "off"
		}					
	} else {
		//Show instant stauts update
		document.getElementById("status").innerHTML = "Paused";	
		autoRotate = "off";
	
		if (action == "first") {
			currentIndex = 0;			//Go to Start of Slideshow
		} else if (action == "previous") {
			if (currentIndex-- <= 0) {
				currentIndex = imagesArray.length - 1;
			}
		} else if (action == "next") {
			if (++currentIndex >= imagesArray.length) {
				currentIndex = 0;
			}
		} else if (action == "last") {
			currentIndex = imagesArray.length - 1;	//Go to End of Slideshow
			//alert("Going to array index: " + currentIndex);
		}

		//update IMG
		document.getElementById(pictureId).src = imagesArray[currentIndex].image.src;
		document.getElementById(pictureId).title = imagesArray[currentIndex].title;

		//update Title / Heading
		document.getElementById("title").innerHTML = imagesArray[currentIndex].title;

		//update the image count "Image X of XX"
		document.getElementById("image_number").innerHTML = "Image " + (currentIndex + 1) + " of " + imagesArray.length;

		//update Picture Description
		document.getElementById(descriptionId).innerHTML = imagesArray[currentIndex].description;
	}
}


