// JavaScript Document	

/* The Phgal object holds all the Photo Gallery data */

// You should only change the last item (imgTimer) but nothing else here

var Phgal   = new Object();// The Photo Gallery Object

Phgal.pix   = new Array(); // Picture List

Phgal.plpix = new Array(); // Preload images

Phgal.imgIndex = 1;        // Current image index 

Phgal.galTimerID = null;   // Timer ID to trigger 'slide changes', null if timer is off

Phgal.imgTimer = 6; 	   // Image change interval in seconds <-- Change this as you want



// Here is the list of pictures (Note - use forward slashes)

// You need to list all your pictures here in the order you want to show them

// The index must go be 01, 02, 03, ...

Phgal.pix[01] = "images/spreads/spread1.jpg";

Phgal.pix[02] = "images/spreads/spread2.jpg";

Phgal.pix[03] = "images/spreads/spread3.jpg";

Phgal.pix[04] = "images/spreads/spread4.jpg";

Phgal.pix[05] = "images/spreads/spread5.jpg";

Phgal.pix[06] = "images/spreads/spread6.jpg";

Phgal.pix[07] = "images/spreads/spread7.jpg";

Phgal.pix[08] = "images/spreads/spread8.jpg";


//----------- Do not change anything below ------------------

Phgal.imgCount = Phgal.pix.length-1; // Number of regular images in list, 1 thru N (Zero not used)



// Public Methods

Phgal.startup = function () { // Init Photo Gallery

	this.updateDisplay( this.imgIndex ); // Initialize Dispaly

	this.start(); 	//Start the Gallery Timer

	return( true );

}



// Private Methods



Phgal.preload_item = function( n ) { // Preloads an individual item

    if ( n > this.imgCount ) { return; }

    if ( this.plpix[ n ]==undefined || !this.plpix[ n ].complete ) {

    	this.plpix[ n ] = newImage( this.pix[ n ] ); 

    }

}



Phgal.updateDisplay = function( ii ) { // Common display update routine

	changeImages( 'GalleryImg', this.pix[ ii ] ) // Main image

    	this.preload_item( ii   ); 

	this.preload_item( ii+1 );

}



Phgal.next = function() { // Called by event timer

    this.reset();	  // Reset timer

    // Advance image

	this.imgIndex++; if (this.imgIndex > this.imgCount) this.imgIndex = 1;

	this.updateDisplay( this.imgIndex );	

    return( true );    

}



Phgal.start = function() { // Start the timer

	if (this.galTimerID) clearInterval( this.galTimerID );

	this.galTimerID = setInterval( "Phgal.next();", this.imgTimer*1000 );

}



Phgal.stop = function() { // Stop the timer

		if ( this.galTimerID ) clearInterval( this.galTimerID );

		this.galTimerID = null;

}



Phgal.reset = function() { this.start() } // Reset the timer

// Currently, Start does a reset, so they are the same function



/* Utility Functions */

function changeImages( arg1, arg2 ) { // Swap an image (used by rollovers

	if( document.images ) { 

		for( var i=0; i<changeImages.arguments.length; i+=2 ) {

			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];

		}

	}

}



function newImage( arg ){ //Create a new image and load it

	if (document.images) { rslt = new Image(); rslt.src = arg; return rslt; } 

}
