$(document).ready(

	function (){
		srzsd.init();
		srzsd.ersetzeAdressen();
		srzsd.weiterlesen();
	}
	
);


var srzsd = {

	init: function (){
	}
	
};

srzsd.ladeCSS = function (href){

	$("<link/>").insertAfter($("head link").eq(-1)).attr({
		href: href,
		rel: "stylesheet"
	});
	
}

srzsd.ladeCSS("/media/styles/js.css");


/*****//* !Weiterlesen *//*****/


srzsd.weiterlesen = function (){

	$(".weiterlesen").each(function(){
	
		var knoten = this;
		
		$(knoten).contents().each(function(){
		
			if (this.nodeType == 8){
			
				var title = knoten.title;
				$(knoten).html(this.nodeValue);
				
				$("a", knoten).click(function(e){
					e.preventDefault();
					
					$(knoten).slideUp(
						200,
						"swing",
						function(){
						}
					);

					$('*[title="' + title + '"]:not(.weiterlesen)').slideDown(
						200,
						"swing",
						function(){
						}
					);

				});
			}
			
		});
		
	});

}


/*****//* !E-Mail-Adressen *//*****/


srzsd.ersetzeAdressen = function (kontext){

	if (kontext == null){
		kontext = document;
	}

	var getEmail = function(string){
		string = string.replace(/ ?\(at\) ?/, "@");
		string = string.replace(/ ?\(punkt\) ?/, ".");
		return string;
	}
	
	$(".epost", kontext).each(function(){
	
		if ($("> a", this).length == 0){
		
			var email = getEmail($(this).html());
			
			if (this.title){
				var betreff = "?subject=" + encodeURI(this.title);
			} else {
				var betreff = "";
			}
			
			$(this).html('<a href="mailto:' + email + betreff + '">' + email + '</a>');
		
		}
		
	});
	
	$(".vcard", kontext).each(function(){
		
		if (this.title){
				
			var link = this.title + ".vcf";
			$(this).removeAttr("title");	
			
			$(this).wrapAll('<a href="' + link + '">');
		
		}
		
	});
	
}

