// tnv.js
// Thumb Nail  viewer
// Draws pic win on the fly
// 10-4 added topAsTable top as table AND topImg if it has an image
// 10-5 added pname on pic, and lable on pic (where pname is on top frame
// 10-6	added bigLink <a href to large picture picwin
// 10-7 added numFrames for topwin
// 10-9	added rollover (or click on thumbnail)
// 10-29 ADD8 add this default
// 11-01 ADD9 added bigLink as a cgi page (using trap);
// 1-06-04 added http://www.lenshouse.net/blankframe file, to make local index work

var MAX_PICS = 128;
var PICS_PER_ROW = 3;
var DEF_HEIGHT = 320;
var DEF_WIDTH = 420;

var callingPageName; 		// main page name
var callingPageUrl; 		// main page url
var bigLink;			// make big img a link
var topAsTable;			// should top be a table
var topImg;			// image on the TOP window
var bigTop;			// text on top (may be same as callingPage)
			// not used if frame != 3
var numFrames;			// if 3 make 3, else, can be blank
var pnameOnPics;		// does pname appear on picWin
var lableOnPics;		// does lable appear on picWin
var rollover;			// true is rollover else click
var doTrap;
var deb;

pic = new Array(MAX_PICS);
tn = new Array(MAX_PICS);
har = new Array(MAX_PICS);
war = new Array(MAX_PICS);
lab = new Array(MAX_PICS);

function makepage(wh)
{
	printTopWin();

	makeThumbs(wh);

	backTo();
} // end makepage()


// top frame 
function printTopWin() // when using 3 frames
{

	// if topwin exist
/*
	if(numFrames != 3)
		return;
*/
	// make sure this exist
	if(typeof(parent.topwin) == 'undefined')
		return;

	with(parent.topwin.document) {
		open();
		writeln('<html>');
		writeln('<head>');
		writeln('</head>');
		writeln('<body>');
		writeln('<center>');

		if(topAsTable == true) {
			addTableToTopWin();
		}
		else {
			writeln('<h1 style= "color: green ; ');
			writeln('font-size: 44; font-family: impact');
			writeln(' height: 150px; ">');
// writeln("<marque width=100>");
// use neon here
			writeln(bigTop);
// writeln("</marque>");
			writeln('</h1> <nobr>');
		}

		writeln('</center>');
		writeln('</body>');
		writeln('</html>');
		close(); 
	} // end with
} // end printTopWin()




/* instead of just a lable
 * This make IMG      Lable     IMG
 */
function addTableToTopWin(tabPic,pn)
{
	if(typeof(parent.topwin) == 'undefined')
		return;

	with(parent.topwin.document) {
		writeln('<table border="1" align="center">');
		writeln('<tr>');
		if(typeof(topImg) != 'undefined') {

			writeln('<td align=center>');

			writeln('<img src="' + topImg + '"');
			writeln(' height=80 width=100 allign=center ');
			writeln('>');
			writeln('</td>');
		} // end if topImg

		writeln('<td>');
		writeln('<H1 STYLE= "color: green ; ');
		writeln('font-size: 30px; font-family: impact ');
		writeln(' height: 150px; " nobr>');
		/*
		writeln('<marquee>');
		writeln('</marquee>');
		*/
		writeln(bigTop);
		writeln('</h1> <nobr>');
		writeln('</td>');

		if(typeof(topImg) != 'undefined') {
			writeln('<td align=center>');
			writeln('<img src="' + topImg + '"');
			writeln(' height=80 width=100 allign=center ');
			writeln('>');
			writeln('</td>');
		} // end if topImg

		writeln('</tr>');
		writeln('</table>');
	} // end with

	return;
} // end addTableToTopWin()


// header on thumbnail page
function thumbhead()
{
//   var the_date = new Date();

	with(parent.thumbwin.document) {

               writeln('<font color="red">');
               writeln('<h4>');
               writeln('Lens Thumbnail Viewer');
               writeln('<font color="black">');
               writeln('</h4>');
               writeln('<h5>');
               writeln('This is Both Java-script');
		writeln('<br>');
               writeln('and');
		writeln('<br>');
               writeln('A perl program');
		writeln('<br>');
               writeln('Which creates a dynamic Java-script');
		writeln('<br>');
               writeln('</h5>');

		writeln('<h4>');
		if(rollover)
			writeln('Place Mouse Over Thumbnail');
		else
			writeln('Click On Thumbnail');
		writeln('<br>');
		writeln('For Large Pictures From');
		writeln('<br>');
		writeln(pname);
//			writeln('<br>');
// document.write('It Is: ' + the_date);

		writeln('<h4>');
	} // end with
} // end thumbhead


function makeThumbs(wh)
{
var i;
var cnt;
	// was if(wh) until 12-29-03
	if(wh == 1) 
		thumbhead();

// loose
// document.writeln( "in thv.js..... before table");

	document.writeln('<table border="0">');
	document.writeln('<tr align="center">');
//	for(var i = 0 ; i < MAX_PICS ; i++) {
	for(i = 0 ; i < MAX_PICS ; i++) {

// document.write(" MAX = " + MAX_PICS);
// document.write(" for i = " + i + " tp = " + typeof(pic[i]) );


		if(typeof(pic[i]) != 'undefined') {
			cnt = cnt + 1;
			document.writeln('<td align="center" width="28%">');
			makeAThumb(i);
			document.writeln("</td>");
			// first time
			if(i == 0) {
				drawPicWin(0);
// document.writeln("after dpw");
			}

			if((( i + 1) % PICS_PER_ROW == 0)) {
				document.writeln('</tr>');
				document.writeln('<tr align="center">');
			} // end if MOD PICS_PER_ROW
		} // end if pic[i] exist
	} // end for i = max_pics
// document.write(" AFTER for i = " + i);

	document.writeln('</tr align="center">');
	document.writeln('</table>');
	if(doTrap) {
		trap();
	}

	return;

} // end makeThumbs()


// makes the <img src = pic[x]..... line
function makeAThumb(num)
{
var x  = "im" + num;
var	h;
var	w;

// document.writeln("in makeAThumb num = " + num);

	if(rollover == true) {
		document.write('<a href="#" ');
		document.write('onmouseover="drawPicWin(' + num + ');');
		document.writeln(' return true">');
	}
	else {
		document.write('<a href="javascript: ');
		document.writeln('drawPicWin(' + num + ')">');
	}


	document.writeln('<img name="' + x + '"');
	if(typeof(lab[num]) != 'undefined')
		document.writeln(' title = "' + lab[num] + '"');
	document.writeln('></a>');

	if(typeof(tn[num]) == 'undefined') {
		document.images[x].src = pic[num];
	}
	else {
		document.images[x].src = tn[num];
	}
	
// loose
	if(typeof(war[num]) == 'undefined' || war[num] > har[num]) {
		w =  100;
		h = 80;
	}
	else {
		h =  100;
		w = 66;
	}
	document.images[x].height = h
	document.images[x].width = w

/*
	if(typeof(har[num]) == 'undefined' || har[num] == 'undefined') {
		har[num] = DEF_HEIGHT;
	}
	if(typeof(war[num]) == 'undefined' || war[num] == 'undefined') {
		war[num] = DEF_WIDTH;
	}
*/

// document.writeln("leaving makeAthumb");

	return;
} // end makeAThumb()




// shows the picture clicked_on
// and lable by redrawing the picwin
//PIC
function drawPicWin(picNum)
{


if(deb) {
alert("in drawPcWin num = " + picNum);
}

/*
if(picNum == 0) {
return;
}
*/
if(deb) {
alert("in drawPicWin() typeof parent.picwin.document = " + typeof(parent.picwin.document));
alert("in drawPicWin() typeof parent.picwin = " + typeof(parent.picwin));
}

	with(parent.picwin.document) {
		open();
		writeln('<html>');
		writeln('<head>');
		writeln('<title>');

// document.writeln("type of lab[" + picNum + " = " + typeof(lab[picNum]));

		if(typeof(lab[picNum]) != 'undefined')
			writeln(lab[picNum]);
		else
			writeln('pic.html');
		writeln('</title>');
	} // end with

	if(doTrap) {
		writeTrap(parent.picwin.document);
	}

	with(parent.picwin.document) {
		writeln('</head>');
		if(doTrap)
			writeln('<body onload="wtrap()">');
		else
			writeln('<body>');
		writeln('<body>');
		writeln('<center>');

		if(pnameOnPics == true) {
			writeln('<h2>');
			writeln(pname);
			writeln('</h2>');
		}

		if(lableOnPics == true) {
			writeln('<h3>');
			if(typeof(lab[picNum]) != 'undefined')
				writeln(lab[picNum]);
			else
				if(typeof(parent.topwin) == 'undefined')
//					if(numFrames != 3)
					writeln('<br><br>');
			writeln('</h3>');
		}

// LEN
			// <a 

/*
what we want
<A HREF="http://www.lenlutz.com/pages/house/index.html" target = "_top">
<img height=80 width=100 allign=center src="http://members.directvinternet.com/l
enlutz1/pics/house/delmar.gif"></A>
*/
		// the image ADD9
		if(bigLink == true) {
			write('<a href="http://www.lenlutz.com/cgi-bin/cgiwrap/lenlutz/bigimg.pl.cgi');
			
			// we may need to convert pic[picNum]
			write('?01-pic=' + pic[picNum] + '" target=_top">');
		}

		writeln('<img name="bigImg"');
		writeln(' src = "' + pic[picNum] + '"');

		// ADD8
		if(typeof(har[picNum]) == 'undefined' ||
					har[picNum] == 'undefined') {

			writeln(' height = 320 ');
			writeln(' width = 420 ');
		}
		else {
			writeln(' height = ' + har[picNum]);
			writeln(' width = ' + war[picNum]);
		}

		if(typeof(lab[picNum]) != 'undefined')
			writeln(' title = "' + lab[picNum] + '"');
		writeln(' >');

		// close a href

		if(bigLink == true) {
			writeln('</a>');

			writeln('<h4><br>Click On Image For Full Size</h4>');
		}

		writeln('</center>');
		writeln('</body>');
		writeln('</html>');
		close(); 
	} // end with

if(deb) {
alert("leaving drawPicWin");
}

	return;
} // end drawPicWin()



function backTo()
{
/* changes with each big picture
		with(parent.thumbwin.document) {
writeln('<a href="javascript:history.back()"');
         writeln('onmouseout="window.status=' + "' ';" + '">BACK</a>');
}
*/


	if(typeof(callingPageUrl) != 'undefined' &&
			typeof(callingPageName) != 'undefined') {
		with(parent.thumbwin.document) {
			writeln('Back to<br>');
			writeln('<a href="' + callingPageUrl + '"  target="_top"> ' + callingPageName + '</a>');
		} // end with
	} // end typeof

/* be nice if this worked, but it doesnt
with(parent.thumbwin.document) {
writeln('<a href="" onClick="history.back()">Back</a>');
} // end with
*/
} // end backTo()

function writeTrap(ww)
{
	with(ww) {

		writeln('<SCRIPT LANGUAGE="JavaScript">');

		writeln('function wright(e)');
		writeln('{');
			writeln('if(navigator.appName == "Netscape" && e.which == 3) {');
			writeln('alert("Now; Just Why Would You Right Click ?");');
			writeln('} // end if netscape');

			write('if(navigator.appName == "Microsoft Internet Explorer" ');
			writeln(' && event.button==2) {');
			writeln('alert("Now; Just Why Would You Right Click ?");');
			writeln('} // end if ie');
			writeln('return false;');

		writeln('} // end wright');

		writeln('function wtrap() ');
		writeln('{');
			writeln('document.onmousedown = wright;');
			writeln('document.onmouseup = wright;');

/*
			writeln('if(document.images) {');
			writeln('for(var i=0;i<document.images.length;i++)');
			writeln('{');
			writeln('document.images[i].onmousedown = wright;');
			writeln('document.images[i].onmouseup = wright;');
			writeln('} // end for');
		writeln('} // end if an image');
*/
		writeln('} // end wtrap');


		writeln('</SCRIPT>');

	} // end with()
} // end writeTrap()
