/**
 * @author Michi
 */

encrypt = function(s){
	var code = "";
	for (var i = 0; i < s.length; i++) {
		var f = s.charCodeAt(i).toString(16);
		if (f.length < 2) 
			f = 0 + f;
		code += f;
	}
	return code;
}

decrypt = function(s){
	var decrypt = "";
	for (var i = 0; i < s.length; i += 2) {
		var f = s.substr(i, 2);
		decrypt += String.fromCharCode(parseInt(f, 16));
	}
	return decodeURIComponent(decrypt);
}

String.prototype.reverse = function(){
	return this.split("").reverse().join("");
}
String.prototype.startsWith = function(str){
	return (this.match("^" + str) == str)
}

jQuery(function($){
	$("a[title^='mail']").each(function(index, element){
		var title = $(this).attr("title").substr("mail".length);
		var mail = decrypt(title);
		$(this).removeAttr("href").removeAttr("title").data("mail", mail).css("cursor", "pointer");
	}).click(function(){
		location.href = "mailto:" + $(this).data("mail");
	});
	
	$("a[href^='mailto:']").each(function(index, elem){
		var mail = $(this).attr("href").substr("mailto:".length).reverse() + "@dpsg-hohenlinden.de";
		$(this).removeAttr("href").css("cursor", "pointer").data("mail", mail);
	}).click(function(){
		location.href = "mailto:" + $(this).data("mail");
	});
	
	$("form").html5form({
		messages: 'de',
		labels: 'hide'
	});
	
	$('a[href$=".jpg"] > img, a[href$=".JPG"] > img, a[href$=".gif"] > img, a[href$=".png"] > img').parent().css({
		'background-position': '0 0',
		'background-image': 'none',
		'padding': '0'
	}).addClass("nobg");
	/*
	 //$("#col3_content").html("");
	 $("a").each(function(){
	 var myHost = location.protocol+"//"+location.host;
	 $(this).css("cursor", "pointer");
	 if($(this).attr("href").startsWith("#")) {
	 $(this).click(function(){
	 $(window).scrollTop($($(this).attr("href")).offset().top);
	 });
	 $(this).removeAttr("href");
	 }
	 });
	 //*/
	$(window).resize(function(){
		$(".page_margins").css("min-height", ($(window).height() - 20) + "px");
	}).resize();
	
	jQuery.fn.elasticArea = function(){
		return this.each(function(){
			function resizeTextarea(){
				this.style.height = this.scrollHeight / 2 + 'px';
				this.style.height = this.scrollHeight + 'px';
			}
			$(this).keypress(resizeTextarea).keydown(resizeTextarea).keyup(resizeTextarea).css('overflow', 'hidden');
			resizeTextarea.call(this);
		});
	};
	/*
	$('.article img[src*="http://www.dpsg-hohenlinden.de"]').each(function(index, ele){
		ele.src = ele.src.replace("/files", "/IMGresize/w"+$(ele).width()+"/files");
	});
	//*/
});

