
// image.js // Copyright Gene Dumas //
// Revised: 07/15/10,121907,111007,021501,112300,07252000,12121999 //


/* Global variables to reset on calling page. */
var OKAY = false; // This MUST be the first line of code!
// OKAY prevents the rollovers from trying to run before the code
// is all initialized. See rollover.js for instructions.
var cPATH = "photos/";// ** "images/"; Image Path (Include the trailing "/".)
var cPREFIX = "100_";// **
var cSUFFIX = "";// **
var cEXT = ".jpg";// **
var iSTARTNUM = 1;// **
var iENDNUM = 24;	// ** Last num or Total num;
var iFILSIZE = 1.267;// ** Average for each file in MB.
var iTOTALFILS;// = iENDNUM - iSTARTNUM + 1;
var iTOTALFILSIZE;// = Math.round( iTOTALFILS * iFILSIZE );
var aFILNAMS = [];// ** 
// ** the vars to be changed in calling '.htm'

/*

For the Love of My Life from the Man who adores you

Thank you for being the love of my life, the wonderful one I adore,
The person who shares all my dreams and desires,
My plans, my adventures, and more!
Thank you for being my very best friend,
my comforter when things g wrong,
the one who encourages, cheers me, believes in me,
changes my "weak" to my "strong".

Thank you for being my partner in life and for filling my heart
with such pride -- I feel like the happiest man
in the world with the woman I love by my side.

Happy Birthday

*/

// Object Methods for image on the page with name = 'IMAGE01' -//

var oIMAGES1 = {};	// Global var for the image object

function nextImg() {

	var iNext,the_image_src;

	iNext = this.ndx + 1;
	if (iNext == this.names.length) iNext = 0;
	the_image_src = this.names[iNext].src;
	document.IMAGE01.src = the_image_src;
	// Works only w/ img name=IMAGE01 not id=IMAGE01
	//document.images[0].src = the_image;
	//document.images.IMAGE01.src='dd2.gif';
	
	this.ndx = iNext;
}

function prevImg() {

	var iNext,the_image_src;

	iNext = this.ndx - 1;
	if (iNext == -1) iNext = this.names.length - 1;
	the_image_src = this.names[iNext].src;
	document.IMAGE01.src = the_image_src;
	this.ndx = iNext;
}

// Constructor function to define an object type,
// that specifies its name, properties, and methods.
function ImgConstr(aNames, iNdx) {

	this.names = aNames || [];
	this.ndx = iNdx || 0;
	this.disp = nextImg;
	this.prev = prevImg;
}
//	this.imgLoad = preLoad || [];

// function loadImages() {

// oIMAGES1.imgLoad; // Load images into memory.

// }


function imagesSet(cPath,aFilNames,preLd) {

var aImagesSrc;

if (document.images) {
//defaultStatus='Click Center Image for Latest Creations!';

if (preLd) {
	//defaultStatus = 'Loading images into memory...';
	window.status = 'Loading images into memory...';
	aImagesSrc = preLoad(aFilNames,cPath);
} else {
	aImagesSrc = AddPath(cPath, aFilnames);
}

// Create an instance of the images object.

oIMAGES1 = new ImgConstr(aImagesSrc,0);

OKAY = true;

} // endif

//defaultStatus = "";
window.status = "";

}// end imagesSet()

//- - - - - - - - - End IMAGE01 object - - - - - - - - -//


// --- Image Functions --- //
function createNames(cPrefix,cSuffix,iStartnum,iEndnum,cExt) {
var aString = new Array();
var iNum = iEndnum - iStartnum + 1;	// Num of images.
var j = iStartnum;

for (var i=0; i<iNum; i++) {	// Create name, add to array.
	aString[i] = cPrefix + j++ + cSuffix + cExt;
}
return aString;
}


function AddPath(cPath, aFilnams) {

	for ( var i = 0; i < k; i++ ) {
		aFilnams[i].src = cPath + aFilnams[i];
	}
return aFilnams;
}


function preLoad(aImgNames,cPath) {

var k = aImgNames.length;
var aImgSrc = new Array(k - 1);


if ( window.document.images ) { // Image swaps or rollovers can work.
	for ( var i = 0; i < k; i++ ) {
		aImgSrc[i] = new Image(); // Create a new image object
		// Set image object's src &		// forces download to browser's cache.
		aImgSrc[i].src = cPath + aImgNames[i];
	}
}
else {
	who("Image swaps or rollovers cannot work.");
}

return aImgSrc;

}


function accessImage(theImage) {

// Pass the image id that you are viewing.var ptheImg = document.getElementById(theImage);
var sMsg = " Image Properties ";
// window.document.ptheImg is undefined.
sMsg += " Src = " + window.document.ptheImg.src;
//  Error:  document.eval is not a function.
// sMsg += " Src = " + document.eval('(' + theImage + ')').src;

/* +
"\n Width  = " + document.eval(theImage).width  +
"\n Height = " + document.eval(theImage).height +
"\n Border = " + document.eval(theImage).border +
"\n Hspace = " + document.eval(theImage).hspace +
"\n Vspace = " + document.eval(theImage).vspace +
"\n TagName = " + document.eval(theImage).name +
"\n Complete = " + document.eval(theImage).complete +
"\n Lowsrc = " + document.eval(theImage).lowsrc +
"\n ProtoType = " + document.eval(theImage).prototype +
"\n OnError = " + document.eval(theImage).onerror +
"\n OnLoad = " + document.eval(theImage).onload +
"\n fileSize = " + document.eval(theImage).fileSize;
*/

alert(sMsg);

/*
border:  Integer that specifies the border width of the image, in pixels.
complete:  Boolean that specifies whether the image has loaded
completely: Successful or not.
fileSize:  Returns the file size of the specified image on the page.
	IE Windows, a numeric string is returned, while in
	IE Mac, a number instead.
	Use it on any image or a loop to cover all images on the page.
	IE only property.
height:  The height of the image.
hspace:  Reflects the "hspace" attribute.
lowsrc:  Reflects the "lowsrc" attribute.
name:	The name of the image as assigned by the "name" attribute.
src:	A read/write string specifying the URL of the image. Example(s).
vspace:  Reflects the "vspace" attribute.
width:  The width of the image.
onabort:  Code is executed when user aborts the downloading of the image.
onerror:  Code is executed when an error occurs with the loading of the
	image (ie: not found).
onload:  Code is executed when the image successfully and completely
	downloads.
*/

//who();
return false;
}

// --- End of Image ()s --- //


// --- Slideshow() functions --- //

var the_TIMEOUT;
var the_SECS = 1000; // 1 second delay between slides.
var the_WIDTH = 0; // > 0 change image width


function prevslide(){

oIMAGES1.prev();
}

function nextslide(){

oIMAGES1.disp();
}


// This function swaps in the next image in the aSLIDESRC array
// and increases the_index by 1.	When array end is reached the
// index is set back to zero.	SetTimeout calls function in 2 secs.

function startShow(){

oIMAGES1.disp(); // Swap image at img name=IMAGE01 to next.
the_TIMEOUT = setTimeout("startShow();",the_SECS);

}


function slideShow(secs) {

if(secs){ the_SECS = secs * 1000; }
//alert("Width=" + window.document.IMAGE01.width);
// Reset width
if(the_WIDTH){ window.document.IMAGE01.width = the_WIDTH; }
//document.IMAGE01.height*=0.25;
if(the_TIMEOUT) {
	clearTimeout(the_TIMEOUT);
	the_TIMEOUT = "";
} else {
	startShow();
}	

}


function chgTimeDelay(iSecs) {

if (iSecs != 0) the_SECS = iSecs * 1000;
// the_SECS = parseInt(window.document.fSLIDE.Seconds.value)*1000;
//window.document.fSLIDE.Seconds.blur();
//alert("the_SECS = " + the_SECS);
return the_SECS;
}


function wedone() {

defaultStatus="";
clearTimeout(the_TIMEOUT);
the_TIMEOUT = "";
self.status='';
//if (!msgWINDOW.closed) msgWINDOW.close();
return true;
}


function setup() {

var aImagesSrc, aFilNames;

iTOTALFILS = iENDNUM - iSTARTNUM + 1;
iTOTALFILSIZE = Math.round( iTOTALFILS * iFILSIZE );

//iBlocker = detectPopupBlocker();
//if (!iBlocker) shoMsg();
chgTxt("mymsg",'Creating Filenames...',sCLASS,1);
window.status = 'Creating Filenames ...';

if (aFILNAMS.length > 0 ) {
	aFilNames = aFILNAMS;
//	alert("Files = " + aFilNames);
} else {
	aFilNames = createNames(cPREFIX,cSUFFIX,iSTARTNUM,iENDNUM,cEXT);
}

if (document.images) {
//defaultStatus='Click Center Image for Latest Creations!';
//defaultStatus = 'Loading images into memory...';
window.status = 'Loading images into memory...';
chgTxt("mymsg",'Loading images into memory...',sCLASS,1);
aImagesSrc = preLoad(aFilNames,cPATH);
// Create an instance of the images object.
oIMAGES1 = new ImgConstr(aImagesSrc,0); // Create & set ndx=0
//if (!msgWINDOW.closed) msgWINDOW.close();
OKAY = true;

} // endif

//defaultStatus = "";
window.status = "";
chgTxt("mymsg",'!',sCLASS,1);
hideDiv("mymsg");// Clear msg;

// Start slideshow
//slideShow(); Error oIMAGES is undefined Line: 265

return 0;
} // end setup() for slideshow;



// --- Misc functions --- //

function myScreen(){

var iWidth, iHeight, iAvailW, iAvailH;

iAvailW = parseInt(window.screen.availWidth);
iAvailH = parseInt(window.screen.availHeight);
iWidth = parseInt(window.innerWidth);
iHeight = parseInt(window.innerHeight);

alert(" screen width = " + iAvailW + "\n screen height = " + iAvailH +
  "\n\n innerWidth = " + iWidth + "\n innerHeight = " + iHeight);

//window.document.IMAGE01.width = iWidth;
//window.document.IMAGE01.height = iHeight;//if (!msgWINDOW.closed) msgWINDOW.close();
return 0;
}


function hideDiv(theID) { // theID is string

var stheDiv,ptheDiv;

//alert("theID = " + theID);
if (document.all)	{ //IE4
	stheDiv = "window.document.all." + theID + ".style";
	ptheDiv = eval(stheDiv);
	ptheDiv.visibility = "hidden";
} else if (document.layers) {	// NS4
	stheDiv = "window.document. " + theID;
	ptheDiv = eval(stheDiv);
	ptheDiv.visibility = "hidden";
} else if (document.getElementById) {	// w3c
	ptheDiv = document.getElementById(theID);
	ptheDiv.style.visibility = "hidden";
} else {
	who(" Sorry, this only works in 4.0+ browsers. ");
}

return;
}


function unhideDiv(theID){

var ptheDiv = document.getElementById(theID);
ptheDiv.style.visibility = "visible";

}


function chgTxt(theElem, sTxt, sClass, iRpl ) {

var thefld;
var oText;
var len;

thefld = document.getElementById(theElem);

if ( thefld ){

len = thefld.childNodes.length;
if ( iRpl === 1 ) len = 0;

if (len > 0) {	// Then Remove text.
	oText = thefld.childNodes[0];
	if ( oText.nodeValue != null )
		thefld.removeChild(oText); // Changes childNodes.length to 0
}
else {
	oText = document.createTextNode(sTxt); // Add text.
	thefld.appendChild(oText);
	if ( sClass ) thefld.className = sClass;
}
} else {
		alert(theElem + "\n theElem is undefined! ");
}

return true;

}


function who(msg) {

var code, app, version, iver, ua;
var sMsg = "";

if (msg) sMsg = msg + "\n";

// Find out what browser this is.
with(navigator) {
	code = appCodeName; 
	app = appName; 
	version = appVersion; 
	iver = parseInt(version); 
	ua = userAgent;
	}
// ua string is a generalized printable string// uastring = app + " " + iver;

sMsg += "This works in Mozilla 3+." +	"\nAppCodeName = " + code
	+ "\nAppName = " + app + "\nAppVersion = " + version
	+ "\nVersionNo. = " + iver + "\nUserAgent = " + ua
	+ "\nUsable Browser = " + OKAY;

alert(sMsg);
return 0;
}

// --- End of Misc Functions --- //


//	Eof
