// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.
// modified: Mike Ilardi
// heavily modified: Arnold Park

// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 1;
PositionY = 1;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 600;
defaultHeight = 450;


// Do not edit below this line...
// ================================

var imgWin;
var options = 'scrollbars=yes,resizable=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;



function popImage(imageURL,imageCredit, imageCaption){

imgWin=window.open('','HonestFred',options);
// for some strange reason, putting in about:blank screws up Safari

with (imgWin.document){
writeln('<html><head><title>Loading Image...</title>');
writeln('<link rel="stylesheet" type="text/css" href="../../templates/style.css"  />');


writeln('<scr'+'ipt>');
// Second Generation Pop Up Image Resizer for "The Fed"
// Script borrowed & modified from npr.org
// Includes slightly modified code from http://www.quirksmode.org/viewport/compatibility.html

/*==========================*/
writeln('function doTitle() {');
writeln('document.title="The Fed - Columbia\'s Real Student Newspaper";');
writeln('}');
/*==========================*/
writeln('function findDOM(objectID,withStyle) { ');
// Variable Declaration for simplicity
writeln('var isLayers = 0; var isAll = 0; var isID = 0;');
	
writeln('if (document.getElementById) {');
writeln('	isID = 1; ');
writeln('} else if (document.all) {');
writeln('	isAll = 1; ');
writeln('} else if ((navigator.appName.indexOf("Netscape") != -1) && (parseInt(navigator.appVersion) == 4)) {');
writeln('	isLayers = 1;');
writeln('}');


writeln('if (withStyle == 1) { ');
writeln('	if (isID) { ');
writeln('		return (document.getElementById(objectID).style); ');
writeln('	} else if (isAll) {');
writeln('		return (document.all[objectID].style);');
writeln('	} else if (isLayers) {');
writeln('		return (document.layers[objectID]);');
writeln('	} else {');
writeln('		return null;');
writeln('	}');
writeln('} else {');
writeln('	if (isID) { ');
writeln('		return (document.getElementById(objectID)); ');
writeln('	} else if (isAll) {');
writeln('		return (document.all[objectID]);');
writeln('	} else if (isLayers) {');
writeln('		return (document.layers[objectID]);');
writeln('	} else {');
writeln('		return null;');
writeln('	}');
writeln('}');

writeln('}');



/*==========================*/
writeln('function ResizeToImage() { ');


writeln('	var dom = findDOM("popoffcontainer",0);');
writeln('	if (!dom) return;');
	// prevents DOM-unsupported browsers from continuing on and sprouting error msgs


writeln('var sbcwnh = 26; // Estimated compensation for scrollbar width and height');

// -- Part 1: Get window in focus and determine diff. btw. inner and outer dimensions
writeln('	window.focus();');

writeln('	window.resizeTo(600,450);');
writeln('	var gap_x = 0, gap_y = 0;');

writeln('	if (window.innerHeight) { // all browsers except IE');
writeln('		gap_x = 600 - window.innerWidth;');
writeln('		gap_y = 450 - window.innerHeight;');
writeln('	} else if (document.documentElement && document.documentElement.clientHeight) { ');// IE 6 Strict Mode
writeln('		gap_x = 600 - document.documentElement.clientWidth;');
writeln('		gap_y = 450 - document.documentElement.clientHeight;');
writeln('	} else if (document.body) { // other IE versions');
writeln('		gap_x = 600 - document.body.clientWidth;');
writeln('		gap_y = 450 - document.body.clientHeight;');
writeln('	}');


	// Corrective measures, in case they're negative numbers.
writeln('	if (gap_x < 0) gap_x = 0;');
writeln('	if (gap_y < 0) gap_y = 0;');



// -- Part 2: Get Width and Height of images, caption box

writeln('	findDOM("popoffcontainer",1).width = document.images[0].width+2;');
	// Necessary for overall containing box width = image's width
	// note: "2" is for the 1px border around img

writeln('	var docWidth = Math.min(document.images[0].width + gap_x + sbcwnh, window.screen.availWidth - 5);');
	// Calc-ing Width of the window

writeln('	var docHeight = Math.min( dom.offsetHeight + gap_y + sbcwnh - 10, window.screen.availHeight - 5);');
	// Calc-ing Height of window

// -- Part 3: Resize!
writeln('	window.resizeTo(docWidth,docHeight);');

writeln('}');
/*==========================*/

writeln('</scr'+'ipt>');

writeln('</head>');
writeln('<body id = "popoffbody" onload="doTitle();self.focus()" onblur="self.close()">');
writeln('<div id="popoffcontainer">');
writeln('<img id="HonestFred" name="HonestFred" class = "popoffimage"  src="'+imageURL+'" onload="ResizeToImage()">');
writeln('<div id="popoffcredit">'+imageCredit+'</div>');
writeln('<div id="popoffcaption">'+imageCaption+'</div>');
writeln('</div></body></html>');
close();		
}

}

