/*
File Name:
   magazine.js
File Description:
   Northwestern Magazine Javascript Functions
File Author:
   <j-morrow@northwestern.edu>
Last Updated:
   3:00pm, November 29, 2006
*/

 
//  Usage: <a onclick="return openwin('URL');" href="URL">Link</a>
function openwin(url) {
	window.open(url,'','width=600,height=400,scrollbars=yes,resizable=yes').focus();
	return false;
}
function openSnapshotWin(url) {
	window.open(url,'','width=600,height=700,scrollbars=yes,resizable=yes').focus();
	return false;
}
function openPhotoWin(url,width,height) {
	//if (width/1 > 800) {width=800;} else {width = width/1 + 20;}
	//if (height/1 > 800) {height=800;} else {height = height/1 + 20}
	if (width/1 > 1) {
		width = width/1 + 20;
		height = height/1 + 20;
	} else {
		width = 640;
		height = 420;	
	}

	window.open(url,'Photo','width='+width+',height='+height+',scrollbars=no,resizable=yes,toolbar=no,menubar=no,status=no').focus();
	return false;
}

/*
writeConsole('Hello from JavaScript!');
function writeConsole(content) {
 top.consoleRef=window.open('','myconsole',
  'width=350,height=250'
   +',menubar=0'
   +',toolbar=1'
   +',status=0'
   +',scrollbars=1'
   +',resizable=1')
 top.consoleRef.document.writeln(
  '<html><head><title>Console</title></head>'
   +'<body bgcolor=white onLoad="self.focus()">'
   +content
   +'</body></html>'
 )
 top.consoleRef.document.close()
}
*/



function popitup2() {
	var newwindow2=window.open('','name','height=200,width=150');
	newwindow2.document.write('<html lang="en"><hEAD><TITLE>Popup</TITLE>');
	newwindow2.document.write('<LINK REL="stylesheet" HREF="">');
	newwindow2.document.write('</hEAD><BODY><p>This is once again a popup.</p>');
	newwindow2.document.write('<p><a href="javascript:alert(self.location.href)">View location</a>.</p>');
	newwindow2.document.write('<p><a href="javascript:self.close()">Close</a> the popup.</p>');
	newwindow2.document.write('</BODY></hTML>');
	newwindow2.document.close();
}


function photoPopup(imgurl,caption,credit,width,height) {
	if (width>800) {width=800;}
	if (height>750) {height=750;}
	height = height+25;
	
	var lphoto = window.open('window.location','name','width='+width+',height='+height+',scrollbars=no,resizable=yes,menubar=no,toolbar=no');
	
	//lphoto.document.open();
	//lphoto.document.write(popupbody);
	lphoto.document.write('<html>Does this work?</html>');
	lphoto.document.close();
	//return false;
	//lphoto.focus();
}

function printLinks(div,arrLinks) {
	if (arrLinks.length > 0) {
		for(x = 0; x < arrLinks.length; x++) {
			document.write(fnode[x]);
			if (x+1 < arrLinks.length) {
				document.write(' ' + div + ' ');
			}
		}			
	}
}
				  
function printPhotos(arrPhotos, p) {
	var n = '';
	var r = 0;
	var arrl = 0;
	arrl = arrPhotos.length;
	//Array(photoSmall,photoLargeU,photoLargeW,photoLargeH,photoDesc,photoAuthor);
	if (arrl > 0) {
		
		n = "<tr>";
		for(x = 0; x < p; x++) {

			n += "<td>";
			
			if (arrPhotos[x][0] != '' && arrPhotos[x][1] != '') {
				n += "<a href='' onclick=\"openPhotoWin('" + arrPhotos[x][1] + "','" + arrPhotos[x][2] + "','" + arrPhotos[x][3] + "'); return false;\">" + arrPhotos[x][0] + "</a>";
			} else if (arrPhotos[x][0] != '') {
				n += arrPhotos[x][0];
			}
			
			if (arrPhotos[x][4] != '') {
				n += "<p><strong>" + arrPhotos[x][4] + "</strong></p>";
			}
			
			if (arrPhotos[x][5] != '') {
				n += "<p><cite>" + arrPhotos[x][5] + "</cite></p>";
			}			
			
			n += "</td>";		
			r++;

			if (r == 2) {
				n += "</tr><tr>";
				r = 0;
			} 
			
		}
		n += "</tr>";
		document.write(unescape(n));
	}
}

function printLeftNav(arrLinks, j) {
	var n = '';
	var r = 0;
	var arrl = 0;
	arrl = arrLinks.length;

	if (arrl > 0) {
		
		n = "<tr>";
		for(x = 0; x < j; x++) {

			n += "<td><a href='" + arrLinks[x][1] + "' title='" + arrLinks[x][0] + "'>" + arrLinks[x][0] + "</a></td>";		
			r++;

			if (r == 3) {
				n += "</tr><tr>";
				r = 0;
			} else {
				if ((arrl-1) != x) {
				n += "<td>/</td>";
				}
			}
			
		}
		n += "</tr>";
		document.write(unescape(n));
	}
}
