(function() {
	if (!document.body) document.body = document.getElementsByTagName("body")[0];
	var anchors = document.body.getElementsByTagName("a"),
		//lightwindow_anchors = {},
		rel;
	for (var i = 0; i < anchors.length; i ++) {
		if (/\.(?:gif|jpeg|jpg|png)$/i.test(anchors[i].href)) {
			if (anchors[i].hasChildNodes() && anchors[i].childNodes.length == 1 && /img/i.test(anchors[i].childNodes[0].tagName)) addClass.apply(anchors[i], ["imagelink"]);
			if (!anchors[i].getAttribute("title") && !anchors[i].title) anchors[i].setAttribute("title", anchors[i].title = jsapi.string.trim(jsapi.dom.getTextContent(anchors[i])) || "Bild");
			rel = (anchors[i].getAttribute("rel") || anchors[i].rel);
			
			// Highslide JS
			anchors[i].setAttribute("rel", anchors[i].rel = rel = "highslide");
			
			// Lightwindow
			/*addClass.apply(anchors[i], ["lightwindow"]);
			if (!rel) anchors[i].setAttribute("rel", anchors[i].rel = rel = "Bildergallerie");
			if (!lightwindow_anchors[rel]) lightwindow_anchors[rel] = {
				length: 0
			};
			if (!lightwindow_anchors[rel][anchors[i].href]) {
				lightwindow_anchors[rel][anchors[i].href] = anchors[i];
				lightwindow_anchors[rel].length ++;
			}
			var classnames = jsapi.dom.attribute(anchors[i], 'class');
			if (classnames) {
				classnames = classnames.split(/\s+/);
				// if attribute 'class' value contains 'lightwindow_altparams' set 'params' attribute
				if (classnames.indexOf('lightwindow_altparams') > -1) {
					jsapi.dom.attribute(anchors[i], 'params', 'lightwindow_width=384,lightwindow_height=620,lightwindow_type=external,lightwindow_iframe_embed=true');
				};
				if (classnames.indexOf('lightwindow') > -1) classnames.forEach(function(oArrayElement, iIndex, oArray) {
					if (oArrayElement.indexOf('lightwindow') < 0) {
						var oHtmlElement = document.getElementById(oArrayElement);
						if (oHtmlElement) jsapi.dom.attribute(this, 'caption', oHtmlElement.textContent || oHtmlElement.innerText);
					}
				}, anchors[i]);
			}*/
		}
		else if (anchors[i].hasChildNodes()) jsapi.dom.walk(anchors[i], function(node) {
			if (node.nodeValue) {
				var innerText;
				innerText = node.nodeValue.split(/\s+/);
				if (innerText.length == 3 && innerText[1] == "‹AT›") {
					// recipient ‹AT› domain -> recipient@domain
					node.parentNode.replaceChild(document.createTextNode(innerText[0] + "@" + innerText.slice(2).join("")), node);
				}
			}
		});
	};
	/*for (var rel in lightwindow_anchors) {
		if (lightwindow_anchors[rel] && lightwindow_anchors[rel].length > 1) {
			for (var href in lightwindow_anchors[rel]) {
				if (lightwindow_anchors[rel][href] && lightwindow_anchors[rel][href].href)
					lightwindow_anchors[rel][href].setAttribute("rel", lightwindow_anchors[rel][href].rel = rel + "[]");
			}
		}
	};*/
})();
