function addEvent(obj, type, fn) {
	// Mozilla/W3C listeners?
	if (obj.addEventListener) {
		obj.addEventListener(type, fn, false);
		return true;
	}

	// IE-style listeners?
	if (obj.attachEvent) {
		return obj.attachEvent('on' + type, fn);
	}

	return false;
}

addEvent(window, 'load', function() {
	if (!document.createElement) {
		return;
	}

	// For each block quote...
	var quotes = document.getElementsByTagName('blockquote');
	for (var i = 0; i < quotes.length; ++i) {
		// ...that includes a citation...
		var cite = quotes[i].getAttribute('cite');
		if (cite != '' && cite != null) {
			// Create a link to the cited resource...
			var a = document.createElement('a');
			a.setAttribute('href', cite);

			var titleNode;
			var title = quotes[i].getAttribute('title');
			if (title == '' || title == null) {
				a.setAttribute('title', cite);
				titleNode = document.createTextNode('Source');
			} else {
				a.setAttribute('title', title);
				titleNode = document.createTextNode(title);
			}
			a.appendChild(titleNode);

			// ...wrap it in a paragraph with class 'source',...
			var p = document.createElement('p');
			p.className = 'source';
			p.appendChild(a);

			// ...and put it at the end of the blockquote.
			quotes[i].appendChild(p);
		}
	}
});

