//
// Filename : dynimages.js
// Author   : Wayne Howarth <wayne@pyesmeadow.fsnet.co.uk>
// Created  : 20th June 2002
//
// Routines for managing the dynamic images.
//
// Assumptions:
//  - The IE4, NS4 and NS6 variables have been assigned to.
//
// Copyright (c) 2002 Wayne Howarth, All Rights Reserved
//
// Routines in this file may be freely distributed providing the above
// copyright message is preserved.
//

var images;
var nextImageIdx;
var imageCount = 7;
var delayMs = 8000;

function ImageObject( strImage, description )
{	//
	// ImagePair
	// Encapsulates a pre-loaded image.
	//

	this.theImage = new Image();
	this.theImage.src = strImage;
	this.description = description;
}

function initialisePictures()
{	//
	// initialisePictures()
	// Called to initialise which pictures are currently displayed
	// and preloads other images to swap with.
	//
	// Also starts the timer ticking.
	//

    images = new Array(
    	new ImageObject( 'images/house2.jpg', 'North elevation' ),
    	new ImageObject( 'images/barneast.jpg', 'Traditional Suffolk barn and out-buildings as viewed from the east' ),
    	new ImageObject( 'images/barnwest.jpg', 'Traditional two-bay Suffolk barn and out-buildings as viewed from the west' ),
    	new ImageObject( 'images/eastside.jpg', 'Lynns Hall as viewed from the east' ),
    	new ImageObject( 'images/tractorshed.jpg', 'Large seven-bay, open-fronted implement shed' ),
    	new ImageObject( 'images/yard.jpg', 'North end of yard with implement shed on left and barn on right' ),
    	new ImageObject( 'images/house_sw.jpg', 'Front of Lynns Hall as viewed from the south-west' )
    );

    nextImageIdx = 1;
    setTimeout( "swapPicture()", delayMs );
}

function swapPicture()
{	//
	// swapPicture()
	// Called when an image on the page should be swapped at
	// random.
	//
	// Assumes:
	//   Global 'images' arrays holds pre-loaded images.
	//

	//
	// Make sure that the images have finished loading.
	//
	if( images[nextImageIdx].theImage.complete )
	{
	   getItem('bottomImage').src = images[nextImageIdx].theImage.src;
	   getItem('pictureCaption').innerText = images[nextImageIdx].description;
	}

    if( ++nextImageIdx == imageCount )
    	nextImageIdx = 0;

    setTimeout( "swapPicture()", delayMs );
}