// If you wish to use this script for non-commercial purposes, please extend the author the courtesy of crediting him and
// providing a link to his site - http://www.markeverett.com

// Unauthorised use of this script for commercial purposes is prohibited.
// Please contact the author at mark AT markeverett D0T com to request authorisation.

// In all cases this work remains the copyrighted property of Mark Everett


// _______________________________________________________________

// Title : Pane constructor v1
// Author : Mark Everett
// Website : www.markeverett.com
// Copyright © Mark Everett 2004 all rights reserved
// _______________________________________________________________

// ' make a panes array to store the Pane objects
var panes =  new Array ();

// ' Pane constructor function
	// ' 
	// ' LIST OF ARGUMENTS
	// ' theElement: the html element that the pane object is associated with
	// ' fromRed, fromGreen, fromBlue: the starting colors of the object
	// ' toRed, toGreen, toBlue: the end colors of the object
	// ' upSteps, downSteps: the number of steps to fade up and down respectively
	// ' upInterval, downInterval: the interval between fade steps, up and down respectively
	// ' zindex: the z-index of the new object (the idNumber of the corresponding element)
	// ' 
function Pane(theElement, fromRed, fromGreen, fromBlue, toRed, toGreen, toBlue, upSteps, upInterval, downSteps, downInterval, zindex) {
	this.element = theElement;
	this.fromRed = fromRed;
	this.fromGreen = fromGreen;
	this.fromBlue = fromBlue;
	this.toRed = toRed;
	this.toGreen = toGreen;
	this.toBlue = toBlue;
	this.redUpStep = (toRed - fromRed) / upSteps;
	this.greenUpStep = (toGreen - fromGreen) / upSteps;
	this.blueUpStep = (toBlue - fromBlue) / upSteps;
	this.redDownStep = (toRed - fromRed) / downSteps;
	this.greenDownStep = (toGreen - fromGreen) / downSteps;
	this.blueDownStep = (toBlue - fromBlue) / downSteps;
	this.upInterval = upInterval;
	this.downInterval = downInterval;
	// ' zindex is set to object's associated idNumber
	this.zindex = zindex;
	// ' upTimer,downTimer: hold the up and down setInterval timer ids
	this.upTimer = "";
	this.downTimer = "";
	// ' currentRed, currentGreen, currentBlue: hold the object's current rgb values
	// ' They are currently initialized with the object's start colors (fromRed etc.)
	// ' The most common approach will probably be to set these values to the enclosing
	// ' element's (usually the body's) background-color -- it may be worth hard-coding
	// ' this into at least one version.
	this.currentRed = fromRed;
	this.currentGreen = fromGreen;
	this.currentBlue = fromBlue;
}

// ' Pane methods
Pane.prototype.fadeUpStep = Pane_fadeup_step;
Pane.prototype.fadeDownStep = Pane_fadedown_step;


// ' Pane fadeup method function
function Pane_fadeup_step () {
	if (this.fromRed < this.toRed) {
		this.currentRed = Math.min(Math.floor(this.currentRed + this.redUpStep),this.toRed);
		
	} else {
		this.currentRed = Math.max(Math.floor(this.currentRed + this.redUpStep),this.toRed);
	}
	if (this.fromGreen < this.toGreen) {
		this.currentGreen = Math.min(Math.floor(this.currentGreen + this.greenUpStep),this.toGreen);
		
	} else {
		this.currentGreen = Math.max(Math.floor(this.currentGreen + this.greenUpStep),this.toGreen);
	}
	if (this.fromBlue < this.toBlue) {
		this.currentBlue = Math.min(Math.floor(this.currentBlue + this.blueUpStep),this.toBlue);
		
	} else {
		this.currentBlue = Math.max(Math.floor(this.currentBlue + this.blueUpStep),this.toBlue);
	}
}

// ' Pane fadedown method function
function Pane_fadedown_step () {
	if (this.fromRed > this.toRed) {
		this.currentRed = Math.min(Math.floor(this.currentRed - this.redDownStep),this.fromRed);
		
	} else {
		this.currentRed = Math.max(Math.floor(this.currentRed - this.redDownStep),this.fromRed);
	}
	if (this.fromGreen > this.toGreen) {
		this.currentGreen = Math.min(Math.floor(this.currentGreen - this.greenDownStep),this.fromGreen);
		
	} else {
		this.currentGreen = Math.max(Math.floor(this.currentGreen - this.greenDownStep),this.fromGreen);
	}
	if (this.fromBlue > this.toBlue) {
		this.currentBlue = Math.min(Math.floor(this.currentBlue - this.blueDownStep),this.fromBlue);
		
	} else {
		this.currentBlue = Math.max(Math.floor(this.currentBlue - this.blueDownStep),this.fromBlue);
	}
}

