/**
 * @author Gregor Aisch, Dave Gööck, Christoph Mewes, Zozi
 * @publisher webvariants GbR
 * @website http://www.webvariants.de/
 * @contact info - webvariants - de
 * 
 * Dieses Script benötigt entweder jQuery (http://www.jquery.com/) oder
 * Prototype (http://www.prototypejs.org/). jQuery wird bevorzugt.
 * 
 * Es werden sowohl die einfache sowie die erweiterte (mit Mail-Titel) mapson Syntax
 * unterstützt. Da das MoreCSS Hyphenation Plugin sämtliche in seinem Einflussbereich
 * befindlichen mapson Nodes ersetzt wurde das hypheneation script um ein callback erweitert,
 * welches hier benutzt wird um nach der Ersetzung die Eventhandler neu zu setzen.   
 * 
 */

function replaceMailToLink(e) {
	var $e = $(e);
	
	var link = title = '';
	if ($('.liam', $e).length > 0) {
		$('.liam span', $e).remove();
		link = $('.liam', $e).text();
		$('.liam', $e).remove();
		title = $e.html();
	}
	else {
		$('span', $e).remove();
		title = link = $e.text();
	}
	
	link = link.replace(/ ?(­|&#173;|&shy;|&#x00AD;) ?/g, "");
	
	$e.replaceWith('<a href="mailto:'+link+'">'+title+'</a>');	
}

function setMapsonEvent() {
	$('span.mapson').unbind('mouseover');
	$('span.mapson').mouseover(function() {
		replaceMailToLink(this);
	});
}

function setHyphenationFunction() {
	if(typeof MoreCSS != 'undefined' && typeof MoreCSS.hyphenation == 'function'){
		var oldHyphenation = MoreCSS.hyphenation;
		MoreCSS.hyphenation = function(element, properties) {
			oldHyphenation(element, properties, function(){ setMapsonEvent(); });
		}
	}
}

if (typeof jQuery != 'undefined') {
	(function($) { /* on dom load... */ $(function() {
		setHyphenationFunction();
		setMapsonEvent();
	}); /* dom loaded */ })(jQuery);
}

