function prepPopUps() {
    var window_width, window_height;
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
        if (links[i].className.match(new RegExp("(^|\\s)(popup|map|figure|photo|data|biblio|video-link|audio-link)(\\s|$)"))) {
            links[i].onclick = setPopUp;
            links[i].onkeypress = links[i].onclick;
        }
    }
}

function setPopUp() {
    var size, width, height, opts;
	if (this.className.match(new RegExp("(^|\\s)(video-link)(\\s|$)"))) {
		var page = this.getAttribute("src") + "/media_popup_view?t=video&fn=" + this.getAttribute("href");
		width = 440;
		height = 525;
	} 
	else if (this.className.match(new RegExp("(^|\\s)(audio-link)(\\s|$)"))) {
		var page = this.getAttribute("src") + "/media_popup_view?t=audio&fn=" + this.getAttribute("href");
		width = 480;
		height = 650;
	}
	else if (this.className.match(new RegExp("(^|\\s)(biblio)(\\s|$)"))) {
		var path_ary = this.getAttribute("href").split("/");
		var id = path_ary.pop();
		var page = path_ary.join("/") + "/bibref_popup_view?bibref=" + id;
		width = 500;
		height = 200;
	} 
	else if (this.className.match(new RegExp("(^|\\s)(data)(\\s|$)"))) {
		var page = this.getAttribute("href") + "/data_popup_view";
		width = 750;
		height = 750;
	}
	else if (this.className.match(new RegExp("(^|\\s)(popup|map|figure|photo)(\\s|$)"))) {
		var page = this.getAttribute("href") + "/image_popup_view";
        if (this.getAttribute("imgsize")) {
            size = this.getAttribute("imgsize").split(",");
            width = parseInt(size[0]) + 45;
            height = parseInt(size[1]) + 275;
        }
        else {
            width = 600;
            height = 600;
        }
	}
	if (width > screen.availWidth) width = screen.availWidth;
	if (height > screen.availHeight) height = screen.availHeight;
	opts = 'width=' + width + ', height=' + height + ', resizable=1, scrollbars=1, status=0'
	window.open(page, '', opts);
	return false;
}

addLoadEvent(prepPopUps);
