
/**
 * Funktion zum crypten der Email-Adresse
 * Diese wird nach Laden des Dokumentes
 *   $(document).ready(()
 * ausgeführt und crypted die Mail-Adresse, sowie den
 * Anzeigetext
 *
 */
 
jQuery.fn.crypt = function () {
	
	return this.each(function(){
	
		var n=0;
		var shift = 2;
		var r="";
		//Hole Inhalt des href-Attributs
		var s = ($(this).attr('href') == undefined) ? "" : $(this).attr('href');
		//mailto: aus dem href-Attribut entfernen
		s = s.replace('mailto:', '');
		
		//Ersetze das @ mit [at] im a-Tag
		var text = ($(this).html() == undefined) ? "" : $(this).html();
		text = text.replace('@','[at]');
		$(this).html(text);	
		
		//Crypten der Buchstaben der Mail-Adresse
		if(s != "") {
			for(var i=0;i<s.length;i++) { 
				n=s.charCodeAt(i); 
				if (n>=8364) {n = 128;}
				r += String.fromCharCode(n-(shift)); 
			}
			//Setzen des href-Attributs mit neuem Wert
			$(this).attr('href', 'mailto:'+r);
		}
	});
};

/**
 * Decrypten der Mail-Adresse
 * Beschreibung siehe oben
 *
 */
jQuery.fn.uncrypt = function() {

	var n=0;
	var shift = 2;
	var r="";
	//Hole Inhalt des href-Attributs
	var s = ($(this).attr('href') == undefined) ? "" : $(this).attr('href');
	
	//mailto: aus dem href-Attribut entfernen
	s = s.replace('mailto:', '');
	
	//Ersetze das @ mit [at] im a-Tag
	var text = ($(this).html() == undefined) ? "" : $(this).html();
	text = text.replace('@','[at]');
	$(this).html(text);	
	
	//Crypten der Buchstaben der Mail-Adresse
	if(s != "") {
		for(var i=0;i<s.length;i++) { 
			n=s.charCodeAt(i); 
			if (n>=8364) {n = 128;}
			r += String.fromCharCode(n+(shift)); 
		}
		//Setzen des href-Attributs mit neuem Wert
		$(this).attr('href', 'mailto:'+r);
	}
}


$(document).ready(function(){
	//Crypten und Decrypten von Mail-Links
	$("a[href^='mailto:']").crypt();
	$("a[href^='mailto']").hover(function() {$(this).uncrypt();}, function() {$(this).crypt();});

	//Wenn IE, dann prev und next-Link in Aktuelles-Detailansicht ausblenden
	//Hack, da dort die Weiterschaltung auf das erste Bild nicht funktioniert, wenn
	if(navigator.appVersion.indexOf('MSI') > 0) {
		$("#nav_pic").css('display','none');
	}

	//Google Map
  	$('#containermap').jmap('init', {mapCenter:[51.708443,8.769161], mapZoom:13, mapEnableType:true, mapShowjMapIcon:false});   	  	
  	//Add Marker	
  	$('#containermap').jmap('addMarker', {pointLatLng:[51.708443,8.769161], pointHTML: "Hier finden Sie das Institut f&uuml;r Kunststofftechnik Paderborn"});
  	
	//Styleswitcher
	//$('#localization ul li a').styleSwitcher(); // Calling the plugin...  	
});

