/* Links
************************/
function extLink() {
	var site = new RegExp(document.domain,'i');
	for(var i = 0; i < document.links.length; i++) {
			if(!site.test(document.links[i].href) || /external/.test(document.links[i].className)) {
				document.links[i].onclick = function() { return!window.open(this.href) }
			}
	}
}
addEvent(window,'load',extLink);
/* Events
************************/
// written by Dean Edwards, 2005
// http://dean.edwards.name/
function addEvent(element, type, handler) {
    if (!handler.$$guid) handler.$$guid = addEvent.guid++;
    if (!element.events) element.events = {};
    var handlers = element.events[type];
    if (!handlers) {
        handlers = element.events[type] = {};
        if (element["on" + type]) {
            handlers[0] = element["on" + type];
        }
    }
    handlers[handler.$$guid] = handler;
    element["on" + type] = handleEvent;
}
addEvent.guid = 1;
function removeEvent(element, type, handler) {
    if (element.events && element.events[type]) {
        delete element.events[type][handler.$$guid];
    }
}
function handleEvent(event) {
    event = event || window.event;
    var handlers = this.events[event.type];
    for (var i in handlers) {
        this.$$handleEvent = handlers[i];
        this.$$handleEvent(event);
    }
}
///
///
///
// pop-up for opening news and project images
var popwin = null;
function popImage(imagesrc,imgwidth,imgheight,alt)
{
	var maxWidth = screen.width - 30;
	var maxHeight = screen.height - 70;
	var winwidth = (imgwidth) ? imgwidth : 500;
	var winheight = (imgheight) ? imgheight : 500;
	var look = '';
	var left = (screen.width/2) - winwidth/2;
 	var top = (screen.height/2) - winheight/2;
	
	// resize window if too large
	if(imgwidth > maxWidth) {
		winwidth = maxWidth;
		look += 'resizable,scrollbars,';	
		left = 0;
	}
	if(imgheight > maxHeight) {
		winheight = maxHeight;
		if(!look) look += 'resizable,scrollbars,';
		top = 0;
	}
	
	look +='width='+winwidth+',height='+winheight+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	if(alt==null) alt = 'Image';
	if (popwin != null && !popwin.closed) popwin.close();
	popwin=window.open("","imgWin",look);
	popwin.document.open();
	popwin.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n');
	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; padding:0; background-color:black; background-image:url(../images/loading.gif);	background-repeat:no-repeat; background-position:center center; }\n');
	popwin.document.write('img { display:block; border:none; }\n');
	popwin.document.write('</style>\n');
	popwin.document.write('</head>\n<body>\n');
	popwin.document.write('<a href="javascript:;" alt="close" onclick="window.close()">');
	popwin.document.write('<img src="'+imagesrc+'" alt="'+alt+'"');
	if(imgwidth) popwin.document.write(' width="'+imgwidth+'"');
	if(imgheight) popwin.document.write(' height="'+imgheight+'"');
	popwin.document.write('></a>\n');
	popwin.document.write('</body>\n</html>');
	popwin.document.close();
	return true;
}
