function init ()	// Call this from onload
{
	myCaption.innerText = "I'm getting the pictures...";
	showStatus.innerText = "Loading..."

	var i = gI;
	// Build an array of the slides to show
	// arrayShow[++i] = new slide ( "fn", "alt/cap", "text", "link" );

  arrayShow[++i] = new slide ( "Misc/CreepingCharlie.jpg", "Blooming Creeping Charlie" );
	arrayShow[++i] = new slide ( "Misc/Jerry.jpg", "Jerry Takes a Spin", "...on the Mad Teacups at Disneyland. His head is also spinning as he learns the secrets of blogging for dollars. Check out his new website: geraldsfuller.com", "http://geraldsfuller.com" );
	arrayShow[++i] = new slide ( "Misc/SpiderPlant.jpg", "Spider Plant", "Flowers shown here about three times larger than life." );
	arrayShow[++i] = new slide ( "Misc/ViewFromMissionViejoTrail.jpg", "El Mirador to Santiago Peak", "The view from one of our favorite walking trails. (Click on the picture, then use the right arrow key to see more)" );
	arrayShow[++i] = new slide ( "Misc/Waterworld.jpg", "Waterworld at Universal Studios", "This is the setting for the live action show based on the Kevin Costner movie. You will see high falls, jet skis, pyrotechnics, and believe it or not, a seaplane landing. (Click on the picture, then use the right arrow key to see more)" );
	arrayShow[++i] = new slide ( "Misc/NuttalsWoodpecker.jpg", "Nuttal's Woodpecker", "A female does it's thing on a Eucalyptus tree.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Nuttalls_Woodpecker.html" );
	arrayShow[++i] = new slide ( "Misc/Jay_0694.jpg", "Jay Bird, September 25, 2007", "Jay poses for the camera on a sunny fall morning." );
	arrayShow[++i] = new slide ( "Misc/IMG_0677.jpg", "Tiny Flowers", "Sorry, I don't know what they are." );
	arrayShow[++i] = new slide ( "Misc/Castle.jpg", "Disneyland Castle", "Seems like everytime we go at night, the castle colors are different.");
	arrayShow[++i] = new slide ( "Misc/Goldfinch.jpg", "Lesser Goldfinch", "These little beauties have been rare visitors in the backyard. On this day, three or four found the seeds on this potted plant to their liking. I only saw one from my distant vantage point on the patio and was surprised to find two in the photo.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Lesser_Goldfinch.html" );
	arrayShow[++i] = new slide ( "Misc/Geranium.jpg", "Geranium", "These flowers are part of the corner garden. I failed to noticed the two long-legged insects until I moved the camera close." );
	arrayShow[++i] = new slide ( "Misc/InsectOnHydrangea.jpg", "Insect on Hydrangea Leaf", "Looks like the same kind of bug seen on the Geraniums" );
	arrayShow[++i] = new slide ( "Misc/lizardonhand.jpg", "Western Fence Lizard", "Aug. 15, 2006: Since we no longer have a cat, there are more lizards as well as birds. I'm always amazed at how small these Western Fence lizards start out.", "http://www.sdnhm.org/fieldguide/herps/scel-occ.html" );
	arrayShow[++i] = new slide ( "Misc/lizardonhand2.jpg", "Western Fence Lizard", "August 7, 2007: Probably the smallest I've seen, shown here about 3 times larger than life." );
	arrayShow[++i] = new slide ( "Misc/caterpillar.jpg", "Caterpillar", "Maybe a Sphinx variety? It was munching on the grapevines on the patio." );
	arrayShow[++i] = new slide ( "Misc/Moth.jpg", "Moth", "Related to the caterpillar? Don't know. This one flew into the house. We captured it under a cloche against the patio door to get a picture before escorting it back outside." );	
	arrayShow[++i] = new slide ( "Misc/Butterfly.jpg", "Butterfly", "Photographed alongside Serrano Road in Whiting Ranch" );
	arrayShow[++i] = new slide ( "Misc/WhitingRanchDeer.jpg", "Mule Deer", "Photographed alongside Serrano Road in Whiting Ranch" );	
	arrayShow[++i] = new slide ( "Misc/CactusFlower.jpg", "Cactus Flower", "Photographed alongside Serrano Road in Whiting Ranch" );
	arrayShow[++i] = new slide ( "Misc/FunnelSpiderWeb.jpg", "Funnel Spider Web", "The trail sides had a great many of these 3 to 6 inch webs." );
	arrayShow[++i] = new slide ( "Misc/Rattlesnake.jpg", "Baby Rattlesnake", "Alongside the creek bed that runs next to Live Oak Trail in Whiting Ranch" );
	arrayShow[++i] = new slide ( "Misc/BiggerWoodpecker.jpg", "Acorn Woodpecker", "This colorful character had staked out a section of the woods around Serrano Cow Trail as his own.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Acorn_Woodpecker.html" );
	arrayShow[++i] = new slide ( "Misc/WoodpeckerInFlight.jpg", "Acorn Woodpecker in Flight", "This is a single frame from a movie taken as the woodpecker flew to a new perch. I just liked the way the trees looked as the camera followed the bird's flight." );
	arrayShow[++i] = new slide ( "Misc/vulture.jpg", "Turkey Vulture", "November 25, 2006: We came across this one at rest while hiking the Coyote Brush Road in Whiting Ranch.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Turkey_Vulture.html" );
	arrayShow[++i] = new slide ( "Misc/Backyard.jpg", "The Backyard", "Where most of the bird pictures were taken. (Use the right arrow key to see more)" );
	arrayShow[++i] = new slide ( "Misc/ScrubJayOnHand.gif", "Jay", "Read 'A Scrub Jay Affair' to learn about my friend Jay.", "JayShow.html" );
	arrayShow[++i] = new slide ( "Misc/Kay4.jpg", "Kay", "Read 'A Scrub Jay Affair' to learn about my friend Jay's companion." );
	arrayShow[++i] = new slide ( "Misc/Hawk.jpg", "Cooper's Hawk", "August 15, 2007: A rather small individual watches the slope behind our backyard from a Eucalyptus tree.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Coopers_Hawk.html" );
	arrayShow[++i] = new slide ( "Misc/Hawkeye.jpg", "I'm Watching YOU!", "August 15, 2007: The small Cooper's Hawk watches ME from a Eucalyptus tree." );
	arrayShow[++i] = new slide ( "Misc/hawkinbirdbath.gif", "Cooper's Hawk Takes a Bath", "August 25, 2003: Bird feeders are very effective at attracting birds. The birds eventually attract predators. This one came around about once a week (that we know of) and stayed for a leisurely bath a few times. We recently learned that immature Red-tailed hawks have similar banded tails, but based on the sound that this and other visiting hawks made, we are fairly sure this is the Cooper's hawk." );	
	arrayShow[++i] = new slide ( "Misc/pheasant.jpg", "Pheasant", "March 23, 2005: Patty photographed this visitor, casual and unhurried, in our side yard." );	
	arrayShow[++i] = new slide ( "Misc/dovesingarden.jpg", "Mourning Doves", "Aug. 14, 2006: This morning Patty noticed a young dove under one of the lounges in the corner garden. We watched for about a half hour as it's mother coaxed it first up on a chair and then finally up here on the back fence.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Mourning_Dove.html" );
	arrayShow[++i] = new slide ( "Misc/gardenspider.jpg", "Garden Spider", "Aug. 23, 2005: For a couple of months last summer this critter made it's living in the hydrangeas.", "http://www.sdnhm.org/fieldguide/inverts/argi-aur.html" );
	arrayShow[++i] = new slide ( "Misc/squirrel070320.jpg", "California Ground Squirrel", "I called this character Rocky when I first coaxed it to take peanuts. It later changed to Roxy when the slope behind the backyard was littered with her five pups.", "http://www.enature.com/flashcard/show_flash_card.asp?recordNumber=MA0121" );
	arrayShow[++i] = new slide ( "Misc/SquirrelKids.jpg", "Two of Roxy's Pups", "...at about six weeks in May 2007." );
	arrayShow[++i] = new slide ( "Misc/Grosbeak.jpg", "Black-headed Grosbeak", "When the grosbeaks appear at our feeders, we know our taxes should be filed. This is one of three males that passed through this year.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Black-headed_Grosbeak.html" );
	arrayShow[++i] = new slide ( "Misc/BlackPhoebe2007-01-13.jpg", "Black Phoebe", "There have been one or two of these cute fellows catching bugs in the our backyard as well as all the adjacent yards for many years.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Black_Phoebe.html" );
	arrayShow[++i] = new slide ( "Misc/WhiteCrownedSparrow.jpg", "White Crowned Sparrow", "Half a dozen or so of these guys are regular visitors in the backyard during April and May.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/White-crowned_Sparrow.html" );
	arrayShow[++i] = new slide ( "Misc/DEJunco.jpg", "Dark-eyed Junco", "Quite a few of these hang around in the winter and spring. You may be surprised to learn, as I was, that the area in California with the highest number of them is Redding (according to the Great Backyard Bird Count).", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Dark-eyed_Junco.html" );
	arrayShow[++i] = new slide ( "Misc/towhee.jpg", "California Towhee", "Never more than two appear in the backyard. I have also seen them in Whiting Ranch and in the Standard Oil reservation in Brea.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/California_Towhee.html" );
	arrayShow[++i] = new slide ( "Misc/Bluebird.jpg", "Western Bluebird", "At the end of a hike in Whiting Ranch this Bluebird was watching from a signpost in the parking area.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Western_Bluebird.html" );
	arrayShow[++i] = new slide ( "Misc/LazuliBuntingmale.jpg", "Lazuli Bunting male", "One day in mid-April I realized I had not seen any Dark-eyed Juncos in awhile, then glanced at the feeder and thought 'There's one now.' But the head didn't seem dark enough so I got the binoculars for a closer look. What a surprise! This bird was something I had never before seen. I ran for the camera, but when I returned it was, of course, gone. Several days later I got this photo through the patio sliding glass door.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Lazuli_Bunting.html" );
	arrayShow[++i] = new slide ( "Misc/LazuliBuntingfemale.jpg", "Lazuli Bunting female" );
	arrayShow[++i] = new slide ( "Misc/Townsends.jpg", "Townsend's Warbler", "One morning while in the midst of my usual newspaper reading and Scrub Jay feeding, this little bird flew under the patio cover so close to my face I felt the rush of air and saw nothing but a blur. She came back in a minute and landed on this table about six feet in front of me. I didn't have time to set the shutter speed correctly before she disappeared, never to be seen again.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Townsends_Warbler.html" );
	arrayShow[++i] = new slide ( "Misc/yellowwarbler1.jpg", "Yellow Warbler", "One spring day I started the fountain and then went inside and took a shower. When I came out, there were a couple of these Yellow Warblers flitting around. They rarely stop moving and seem to be very shy.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Yellow_Warbler.html" );
	arrayShow[++i] = new slide ( "Misc/PacificSlopeFlycatcher.jpg", "Pacific Slope Flycatcher", "Pacific Slope Flycatcher","The one is an occasional visitor at the backyard fountain, where he perched for about two seconds for this picture.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Pacific-slope_Flycatcher.html" );
	arrayShow[++i] = new slide ( "Misc/Woodpeckers.jpg", "Nuttall's Woodpeckers", "Woodpeckers have been occasional visitors in the Eucalyptus trees on the slope behind our house over the years. For the last month or so (May 2007) they have been heard several times daily.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Nuttalls_Woodpecker.html" );
	arrayShow[++i] = new slide ( "Misc/BlackthroatedGrayWarbler.jpg", "Black-throated Gray Warbler", "The backyard fountain pulled in another previously undetected species.", "http://www.birds.cornell.edu/AllAboutBirds/BirdGuide/Black-throated_Gray_Warbler.html" );

	buildThumbs ();
	Mode.style.display = "block";	// Show the thumbnail button
	gI = i;
	myImage.onmouseover = myStop;
	myImage.onmouseout = myStart;
	myStart ();
}

// Global variables
var arrayShow = new Array();	// Array to hold the slides
var gI=-1;						// Current slide number
var tID = "none";				// Timer ID
var vdir = 'fwd';				// Direction to run
var mtlCnt = 0;					// Empty link count

// Slide constructor
function slide ( image, caption, text, link )
{
	var oImg = new Image;
	
	// Image source URL
	oImg.src = image;
	this.image = oImg;
	// Alt text for the image
	this.alt = caption;
	// The caption that appears immediately below the picture
	this.caption = caption;
	// Descriptive text
	this.text = text;
	// Hyperlink for more info
	this.link = link;
}

function myStop ()
{
	// Stop the timer
	if ( tID != "none" )
	{
		window.clearInterval ( tID );
		tID = "none";
	}
	showStatus.innerText = "Stopped - mouse-out to resume";
	
	// Expand the picture
	myImage.className="large";

	if ( arrayShow[gI].text > "" )
	{
		Cnt.innerText = arrayShow[gI].text;
	}
	else
	{
		Cnt.innerText = ( gI + 1 ) + " of " + arrayShow.length;
	}
}

function myStart ()
{
	myImage.className="normal";
	Big.style.display = "block";
	CntlInfo.style.display = "block";
	step( vdir );
	Cnt.innerText = ( gI + 1 ) + " of " + arrayShow.length;
	if ( tID != "none" )
	{
		window.clearInterval ( tID );
	}
	tID = window.setInterval ( "step( vdir )", 9000 );
	showStatus.innerText = "Running - Mouse-over to stop";
}

function Reverse ()
{
	if ( vdir == 'fwd' )
	{
		vdir = 'rev';
	}
	else
	{
		vdir = 'fwd';
	}
}

function step ( direction )
{
	if ( direction=='fwd' )
	{
//		showDir.innerText = "Forward - click to reverse";
		if ( ++gI == arrayShow.length )	// Wrap around to the beginning again
		{
			gI = 0;
		}
	}
	else
	{
//		showDir.innerText = "Reverse - click to go forward";
		if ( --gI < 0 )	// Go to the last slide
		{
			gI = arrayShow.length - 1;
		}
	}
	if ( myImage.filters !=undefined )	// Filters are IE only
	{
		myImage.filters[0].apply();
	}
	myImage.src = arrayShow[gI].image.src;
	myImage.alt = arrayShow[gI].alt;
	if ( arrayShow[gI].link > "" )
	{
		myLink.href = arrayShow[gI].link;
		myLink.innerText = "More about " + arrayShow[gI].alt;
		mtlCnt = 0;
	}
	else
	{
		if ( ++mtlCnt > 2 )
		{
			myLink.href = "";
			myLink.innerText = "";
		}
	}
	if ( myImage.filters !=undefined )	// Filters are IE only
	{
		myImage.filters[0].play();
	}
	myCaption.innerText = arrayShow[gI].caption;
	if ( ( tID == "none" ) && ( arrayShow[gI].text > "" ) )
	{
		Cnt.innerText = arrayShow[gI].text;
	}
	else
	{
		Cnt.innerText = ( gI + 1 ) + " of " + arrayShow.length;
	}
}

function ShowThumbs ()
{
	thumbnails.style.display = "block";
	Mode.style.display = "none";
	Big.style.display = "none";
	CntlInfo.style.display = "none";
	mtlCnt = 3;
}

function buildThumbs ()
{
	//groups = 0;	// Prepare for the boundary rules
	for ( var n=0;n < arrayShow.length ;n++ )	// Create thumbnail image elements and add them to the page
	{
		var tn = document.createElement ( "img" );
		tn.src = arrayShow[n].image.src;
		tn.alt = arrayShow[n].alt;
		tn.hspace = 4;
		tn.vspace = 4;
		tn.style.cursor = "hand";
		tn.onclick = startshow;
		tn.onmouseover = expand;
		tn.onmouseout = shrink;
		var ir = tn.width / tn.height;
		tn.style.pixelHeight = 50;
		tn.style.pixelWidth = 50 * ir;	//	Should not be necessary but bad things happen otherwise
		thumbnails.appendChild ( tn );
/*		if ( n == boundary[groups] )
		{
			tn = document.createElement ( "hr" );
			tn.size = 5;
			tn.className = "bhr";
			groups++;
			thumbnails.appendChild ( tn );
		}*/
	}
}

function expand ()
{
	this.style.pixelHeight += 8;
	this.style.pixelWidth += 8;
	this.hspace = 0;
	this.vspace = 0;
}

function shrink ()
{
	this.style.pixelHeight -= 8;
	this.style.pixelWidth -= 8;
	this.hspace = 4;
	this.vspace = 4;
}

function startshow ()
{
	var bFound = false;
	for ( var n = 0; n < arrayShow.length; n++ )
	{
		var str = new String;
		str = this.src;
		//alert ( "this.src='" + str + "':arrayShow[" + n + "].image='" + arrayShow[n].image + "'" );
		var idx = str.indexOf ( arrayShow[n].image.src );
		
		if ( idx > -1 )	// Found it
		{
			bFound = true;	
			gI = --n;
			thumbnails.style.display="none";
			myStart ();
			Mode.style.display="block";
			break;
		}
	}
	if ( !bFound )
	{
		alert ( "Src file not found!" );
	}
}

window.onload = init;
