// JavaScripts for nancyboren.com

//--------------------------------------------------------
// Active Page Button

function activePage(button)
{
	 document[button].src = document.getElementById(button).src.replace('.gif', 'H.gif');
	 document[button].onmouseout=null;
	 document[button].onmouseup=null;
	 document[button].onmouseover=null;
}


//--------------------------------------------------------
function preloadImgs() {
	var d=document,a=arguments;
//	alert("preloadImgs d="+d+"  a="+a);	// test
	if(!d.imgs) d.imgs=new Array();
	for(var i=0; i<a.length; i++) {
		d.imgs[i]=new Image;
		d.imgs[i].src=a[i];
	}
}
// make global variables
var gH;
var gW;

//--------------------------------------------------------
// Display picture in 'Main'
function resizePic() {
	var mainW= 861;				// default Main width
	var mainH= 400;				// default Main height
	var p = document.getElementById("pic");
	if (!p) return;				// picture not loaded

//alert("Pic Loaded");
	
	// fix for quirks in IE6
	if (!p.width)				// fix for IE quirk
		p.style.display="inline";

	gH = p.height;				// set globals, used in picFullSize()
	gW = p.width;			

	// Special case for Monotype Article, use wider width to read article
	if (p.src.indexOf("article1.jpg") > 0 ||
		  p.src.indexOf("article2.jpg") > 0 || 
		  p.src.indexOf("article3.jpg") > 0)
	{
		var flag = 1;			// force resize to width
		mainW = 1200;			// make area wider
//alert("Article Page");
	}

	var ratioW = mainW / p.width;
	var ratioH = mainH / p.height;

//alert("pH:"+p.height+" pW:"+p.width+"  rH:"+ratioH+" rW:"+ratioW);

	if (ratioH < 1 || ratioW < 1)		// adjust pic to fit Main area
	{
		if ((ratioH > ratioW) || flag)	// adjust to smaller ratio
		{
			p.height = gH * ratioW;		// adjust to width
			p.width = gW * ratioW;
//alert("Adjust Width: pH:"+p.height+" pW:"+p.width+"  rH:"+ratioH+" rW:"+ratioW);
		} else {
			p.height = gH * ratioH;		// adjust to height
			p.width = gW * ratioH;		// p.width *= ratioW  doesn't work right in IE6
						// p.height *= ratioH  doesn't work right in IE6
//alert("Adjust Height: pH:"+p.height+" pW:"+p.width+"  rH:"+ratioH+" rW:"+ratioW);
		}
	}

	p.style.display="inline";
}

//--------------------------------------------------------
// Display picture in seperate window
function picFullSize() {

	var d=document; 
	var a=arguments; 
	var s=screen;
	var p = document.getElementById("pic");
//alert("p.src="+p.src);

	var displayH = s.availHeight;
	var displayW = s.availWidth;
//	var picH = p.height;
//	var picW = p.width;
	var picH = gH;		// get pic height from global variable
	var picW = gW;		// get pic width from global variable

	var ratioW=displayW/picW;
	var ratioH=displayH/picH;
//alert("dH:"+displayH+" dW:"+displayW+"  pH:"+picH+" pW:"+picW+"  rH:"+ratioH+" rW:"+ratioW);

	if (ratioH < 1 || ratioW < 1)		// adjust pic down to fit displaylay
	{
		if (ratioH < ratioW)			// adjust to smaller ratio
		{
			picH *= ratioH;			// adjust to height
			picW *= ratioH;
		} else {
			picH *= ratioW;			// adjust to width
			picW *= ratioW;
		}
	}
//alert("dH:"+displayH+" dW:"+displayW+"  pH:"+picH+" pW:"+picW+"  rH:"+ratioH+" rW:"+ratioW);

	var newWin= open("", "", "width="+parseInt(picW*.95)+", height="+parseInt(picH*1.1));

  // open document for further output
	newWin.document.open();

  // create document
	newWin.document.write("<html><head><title>"+p.alt+"</title>");
	newWin.document.write('<link href="nb-web.css" rel="stylesheet" type="text/css">');

	newWin.document.write("</head><body onblur='window.close()' onclick='window.close()'>");
//  newWin.document.write("</head><body>");		// Debug - This line disables the onclick event

	newWin.document.write("<div class='instruct'  >Click image to close window</div>");
	newWin.document.write("<div class='fullpic'>"+p.alt+"<br>");

/*
// Debug
scaled = ((picW*.86) / gW) * 100;
if (scaled > 100) {
	direction = "UP by";
} else {
	direction = "DOWN to";
}
newWin.document.write("Image Width: "+parseInt(gW)+" &nbsp;&nbsp; Height: "+parseInt(gH)+"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resized to Width: "+parseInt(picW*.86)+" &nbsp;&nbsp; Height: "+parseInt(picH*.86)+"<br>");
newWin.document.write(" Scaled "+direction+" "+scaled.toFixed(2)+"%<br>");
*/

	newWin.document.write("<img src="+p.src+" width="+parseInt(picW*.86)+" height="+parseInt(picH*.86));
	newWin.document.write("</div>");
	newWin.document.write("</body></html>");

  // close the document - (not the window!)
	newWin.document.close();
	return -1;
}

// End-Of-File


