//INTRODUCTION

//Supplemental Variables
//Twelve variables are defined and initialized in the external javascript file
//loaded above ("history.js).  This file is produced by the WebBridge application.
//Although comments on this page may refer to images in .png format, the .gif format
//is alternatively supported.  The expected format is indicated by a variable in the
//"history.js" file.  Here are the explanations for all of the variables:

//dStart = The commencement date of data logging as yyyymmdd
//mStart = The commencement month of data logging as yyyymm
//yStart = The commencement year of data logging as yyyy
//dTrans = The transition date to the public server (not used in this page)
//mTrans = Transition date year and month (not used in this page)
//yTrans = Transition year (not used in this page)
//privPath = Path to charts on the private server
//publPath = Path to charts on the public server (not used in this page)
//fileType = Expected graphic file format, .PNG or .GIF
//siteTitle = Official title of the PV plant (not used in this page)
//subTitle1 = Subtitle line 1 for the history page (not used in this page)
//subTitle2 = Subtitle line 2 for the history page (not used in this page)


//About Dynamic Image Replacement
//This page opens with two image positions to accommodate a daily power chart and an
//energy production bar chart for the 31 most recent daily periods.  The 31 day production
//chart has an associated image map from which the respective daily power chart can be
//selected by the viewer with mouseover on the appropriate bar.

//Many images appear on this page, however as many as 31 power chart images are not
//inventoried in the document.images[] array.  Instead they are preloaded into the
//browser's cache by javascript statements.  The opening power chart image, loaded by
//an HTML statement and inventoried in the document.images[] array, is the power chart
//for the current production day.  It serves as an image placeholder.  Subsequent viewer
//activity will invoke script to manipulate the properties of this placeholder, replacing
//it with with selected preloaded images for earlier power charts.  The replacements,
//imposed by the script and drawn from the browser's cache, will not become part of the
//document.images[] array since they are only known as properties to the placeholder image.


//Preloaded images
//The preloaded images are the 31 most recent power charts including that for the current
//day, loaded in ascending chronological order.  All are 588 by 112 pixel dimensions.

//END OF INTRODUCTION


//Define array to receive SRC, WIDTH, and HEIGHT attributes for the images
//as they are preloaded into the browser cache by script.

var Set31Days = new Array(31); //up to 31 daily power charts selectable from the 31 day chart
var limit = Set31Days.length;

//More global variables

var dateNow = new Date(); //Initializes to current date
var fetchDay = new Date(dateNow - 2592000000); //Move 30 days back in time.
var loopDay; //Day for current pass through loop.
var yyyyFetch; //"yyyy" for current pass through loop.
var mmFetch; //"mm" for current pass through loop.
var ddFetch; //"dd" for current pass through loop.
var ymdDate; //yyyymmdd for current pass through loop.

//Load the set of power chart images into the browser cache corresponding to
//the most recent 31 days, substituting a blank image for any days prior
//to "dStart".  Inventory the properties into the Set31Days[] array.

var i;
for (i = 0; i < limit; i++)
{
	loopDay = fetchDay.getDate();
	yyyyFetch = String(fetchDay.getFullYear());
	mmFetch = String(fetchDay.getMonth() + 101).substr(1,2); //Leading 1 preserves leading zero for string conversion.
	ddFetch = String(fetchDay.getDate() + 100).substr(1,2); //Date has no offset like month does.
	ymdDate = yyyyFetch + mmFetch + ddFetch;

	if(ymdDate < dStart) //If prehistoric load a blank image
	{
		Set31Days[i] = new Image(588,112);
		Set31Days[i].src = "images37/blackfill" + fileType;
	}
	else //Acceptable date
	{
		Set31Days[i] = new Image(588,112);
		Set31Days[i].src = privPath + yyyyFetch + "/" + yyyyFetch + mmFetch + "/" + String(ymdDate).substr(2,6) + fileType;
	}
	fetchDay.setDate(loopDay + 1);
}

//Define functions to manipulate the source property of the placeholder image,
//replacing it with the source property of other images selected by the viewer.
//In this way any selected image will be displayed at the placeholder position.
//The index number, n, corresponding to the selected image is passed.

function showD(n)
	{
		document.images["chartpwr"].src = Set31Days[n].src;
	}
