/*
 * Dynamically create a link to update the current page. 
 * Each template file should have a line like this:
 *
 * <!-- com.omniupdate.ob --><!-- /com.omniupdate.ob -->
 *
 * That line should go just before the closing body tag.
 *
 * Omniupdate will dynamically replace this tag with a link, wrapped
 * around a 1px transparent gif. The line of code containing the link is
 * customizable in Setup > Web Sites. This script dynamically replaces
 * our copyright link's href with the href that OU inserts for us. 
 */

if (!JEJ)
	var JEJ = {};

if (!JEJ.doubledelegate) {
	JEJ.doubledelegate = function(f1, f2) {
		return function() {
			if (f1)
				f1();
			if (f2)
				f2();
		}
	}
}

var HOOK = {};

HOOK.switchhook = function () {
	var h = document.getElementById('ouhook');
	if (!h)
		return;
	var u = window.location.href;
	if (u.indexOf('path=') != -1) 
		return;
	if (u.indexOf('http://mansueto.lib.uchicago.edu') == 0)
		u = u.substring(32);
	if (u.lastIndexOf('/') == u.length - 1)
		u = u + 'index.html';
	u = h.href + '&path=' + encodeURIComponent(u);
	var lnks = document.links;
	for (var i=0; i<lnks.length; i++) {
		if (lnks[i].id == "copylink") {
			lnks[i].href = u;
		}
	}
}
window.onload = JEJ.doubledelegate(window.onload, HOOK.switchhook);
