// Javascript to run after the document is loaded

function externalLinks(){
	// If any links are not in the current domain, force them to open in a new window & add another CSS class.
	var _a = document.body.getElementsByTagName('a');
	var _c = window.location.href.split('/')[2];

	for(var i=0;i<_a.length;i++){
		if(_a[i].href.indexOf(_c)==-1
		   && _a[i].href.indexOf('http:')==0 && _a[i].href.length>0){
			_a[i].setAttribute('target','_blank');							// target
			_a[i].className = _a[i].className+' ext';						// class to add icon
			if(_a[i].title.length>0) _a[i].title+=' ';
			_a[i].title+=' (Opens in a new window) ';// title
		}
		if(_a[i].href=='#') _a[i].href='javascript:void(0);';
	}
}

externalLinks();

// pop-up for opening news and project images
var popwin = null;
function popImage(imagesrc, winwidth, winheight, alt){
 	var left = (screen.width/2) - winwidth/2;
 	var top = (screen.height/2) - winheight/2;
 	var look='width='+winwidth+',height='+winheight+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	
 	if(winwidth>screen.width || winheight>screen.height) {
		winwidth = screen.width-11;
		winheight = screen.height-68;
		left = 0;
		top = 0;
		look="resizable,scrollbars,height="+winheight+",width="+winwidth+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	}
	  
	if (popwin != null && !popwin.closed) popwin.close();
	popwin=window.open("","imgWin",look);
	popwin.document.open();
	popwin.document.write('<html>\n<head>\n');
	popwin.document.write('<title>'+alt+'</title>\n');
	popwin.document.write('<style type="text/css">\n');
	popwin.document.write('body { width:100%; height:100%; margin:0; background-color:#000; cursor:pointer; }\n');
	popwin.document.write('</style>\n');
	popwin.document.write('</head>\n<body marginwidth="0" marginheight="0" onclick="window.close()">\n');
	popwin.document.write('<img src="'+imagesrc+'" alt=""  width="'+winwidth+'" height="'+winheight+'" border="0" title="Close">\n');
	popwin.document.write('</body>\n</html>');
	popwin.document.close();
}

function popVideo(src, winwidth, winheight, alt){
 	var left = (screen.width/2) - winwidth/2;
 	var top = (screen.height/2) - winheight/2;
 	var look='width='+winwidth+',height='+winheight+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	
 	if(!winwidth || !winheight) {
		winwidth = 420;
		winheight = 315;
		left = (screen.width/2) - winwidth/2;
		top = (screen.height/2) - winheight/2;
		look="resizable,height="+winheight+",width="+winwidth+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
    //winwidth = '100%';
		//winheight = '100%';
	}
	  
	if (popwin != null && !popwin.closed) popwin.close();
	popwin=window.open("","vidWin",look);
	popwin.document.open();
	popwin.document.write('<html>\n<head>\n');
	popwin.document.write('<title>'+alt+'</title>\n');
	popwin.document.write('<style type="text/css">\n');
	popwin.document.write('body { margin:0; background-color:#000 }\n');
	popwin.document.write('</style>\n');
	popwin.document.write('</head>\n<body marginwidth="0" marginheight="0">\n');
	popwin.document.write('<OBJECT ID="MediaPlayer" WIDTH="'+winwidth+'" HEIGHT="'+winwidth+'" CLASSID="CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95" STANDBY="Loading Windows Media Player components..." TYPE="application/x-oleobject">' +
	  '<PARAM NAME="FileName" VALUE="'+src+'">' +
    '<PARAM name="autostart" VALUE="true">' +
    '<PARAM name="ShowControls" VALUE="true">' +
    '<param name="ShowStatusBar" value="false">' +
    '<PARAM name="ShowDisplay" VALUE="false">' +
    '<EMBED TYPE="application/x-mplayer2" SRC="'+src+'" NAME="MediaPlayer" WIDTH="'+winwidth+'" HEIGHT="'+winwidth+'" ShowControls="1" ShowStatusBar="0" ShowDisplay="0" autostart="1"></EMBED>' +
    '</OBJECT>');
	popwin.document.write('</body>\n</html>');
	popwin.document.close();
}