DOM = jsapi.dom;

log = function() {
};

(function() {
	if (!document.body) document.body = document.getElementsByTagName("body")[0];
	var anchors = document.body.getElementsByTagName("a"),
		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].getElementsByTagName("img").length) {
				anchors[i].className += " 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");
		}
		else {
			var href = decodeURI(anchors[i].href).split(/\s+/);
			if (href.length == 3 && href[1] == "‹AT›") anchors[i].href = href[0] + "@" + href.slice(2).join("");
			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);
					}
				}
			});
		}
	};

	jsapi.dom.append(document.body, jsapi.dom.parseString('<div id="controlbar" class="highslide-overlay controlbar">' +
		'<a href="#" class="previous" onclick="return hs.previous(this)" title="Vorheriges Bild (Pfeiltaste links)"></a>' +
		'<a href="#" class="next" onclick="return hs.next(this)" title="Nächstes Bild (Pfeiltaste rechts)"></a>' +
			'<a href="#" class="highslide-move" onclick="return false" title="Klicken und ziehen zum Bewegen"></a>' +
			'<a href="#" class="close" onclick="return hs.close(this)" title="Schließen"></a>' +
	'</div>'));
	
	// Highslide JS
	hs.registerOverlay(
			{
				thumbnailId: null,
				overlayId: 'controlbar',
				position: 'top right',
				hideOnMouseOut: true
		}
	);
	
	hs.align = 'center';
	hs.graphicsDir = './js/highslide/graphics/';
	hs.outlineType = 'rounded-white';
	hs.captionEval = '(this.a.title || this.thumb.title || jsapi.dom.getTextContent(this.a)) + " (" + this.a.number + " von " + hs.count + ")";';
	
	hs.previousText = '';
	hs.nextText = '';
	hs.moveText = '';
	hs.closeText = '';

})();
