var dotIR = {
	replaceElement: function(selector, colour, background, width, align, size, font, parentElement) {
		var nodes = Selector.findChildElements(parentElement || document, [selector]);
		nodes.each(function(node) {
			// drop inside anchor if exists
			if(node.firstChild && node.firstChild.tagName && node.firstChild.tagName.toLowerCase() == 'a')
				node = node.firstChild;

			// skip replaced nodes
			if(node.hasClassName('dotIR-replaced')) return;
			node.addClassName('dotIR-replaced');

			var lines = node.innerHTML.split(/<br *\/*>/i);
			node.innerHTML = '';
			lines.each(function(line) {
				var params = {
					t: line.strip().stripTags().unescapeHTML().replace(/&nbsp;/g, ' '),
					w: width,
					fc: colour,
					bc: background,
					align: align,
					fs: size,
					fn: font
				}
				var span = node.appendChild(new Element('span'));
				span.appendChild(new Element('img', {
					src: 'http://uk.zopa.com/dotIR/IrImageHanler.ashx?' + $H(params).toQueryString(),
					alt: line
				}));
			});
		}, this);
	}
}

function zopaIr(event) {
	var baseColour = '#c70303';
	dotIR.replaceElement("body.community h1.dotIR", baseColour, "#fff", 440, "left", 36, "AgBuch.ttf", event.target);
	dotIR.replaceElement("body.community h2.dotIR", baseColour, "#fff", 440, "left", 20, "AgBuch.ttf", event.target);
	dotIR.replaceElement("body.community h3.dotIR", "#b7b3a1", "#fff", 300, "left", 20, "AgBuch.ttf", event.target);
};

document.observe('document:contentLoaded', zopaIr);