var newWindow = null;

function popUpWin() {

	if (typeof(chrome) == 'undefined') chrome = 0;

	closeWin();  // check to see if there is an existing window

	if (projectW == 0 && projectH == 0) {
	  if (windowSameSize == '1') {
		  type = 'samesize';
		} else {
	    type = 'fullScreen';
		}
	}
	else {
	  type = 'console';
	}

	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;    // add a very small amount of wiggle room
		strHeight = screen.availHeight - 10;  // add a very small amount of wiggle room
	}

	var x = (screen.availWidth - projectW) /2;
	var y = (screen.availHeight - projectH)/3;

  var myChrome = (chrome == 1) ? 'yes' : 'no';
	var tools="toolbar="+myChrome+",statusbar="+myChrome+",location="+myChrome+",menubar="+myChrome+",";

	if (type == "fullScreen") {
	  tools += "scrollbars=yes,resizable=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";

	} else if (type == "console") {
	  tools += "scrollbars=";
		tools += ('1' == scrollbars) ? 'yes' : 'no';
		tools += ",resizable=yes,width="+projectW+",height="+projectH+",left="+x+",top="+y+"";

	} else {
	  tools += "scrollbars=yes,resizeable=yes";
	}

	newWindow = window.open(projectUrl, '_blank', tools);
	newWindow.focus();

}

function popUpES() {

	var x = (screen.availWidth - 815) /2;
	var y = (screen.availHeight - 520)/3;

	tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+815+",height="+520+",left="+x+",top="+y+"";
	newWindow = window.open('../editorialStatement.html', 'newWin', tools);
	newWindow.focus();
}

function popTester(url, width, height) {

	var x = (screen.availWidth - width) /2;
	var y = (screen.availHeight - height)/3;

	tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+width+",height="+height+",left="+x+",top="+y+"";
	newWindow = window.open(url, 'testerWin', tools);
	newWindow.focus();
}

function closeWin() {
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function revEmail() {
  // adapted from code by John Bell.
  var i;
  var j;
  var sp = document.getElementsByTagName('SPAN');
  for (i = 0; i < sp.length; i++){
    if (sp[i].className == 'mail') {
      var reversed = sp[i].innerHTML;
      var address = '';
      for (j = reversed.length - 1; j >= 0; j--) address += reversed.charAt(j);
      sp[i].innerHTML = '<a href="mailto:'+address+'">'+address+'</a>';
			sp[i].style.visibility = 'visible';
    }
  }
}

function preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}
function mySwap (flag,to) {
  document.images[flag].src = to;
}

function swapProjectListContentToText(what) {
  document.getElementById('projectImageDiv'+what).style.visibility = 'hidden';
	document.getElementById('projectLinkDiv'+what).style.visibility = 'visible';
}

function swapProjectListContentToImage(what) {
  document.getElementById('projectImageDiv'+what).style.visibility = 'visible';
	document.getElementById('projectLinkDiv'+what).style.visibility = 'hidden';
}