// JavaScript Document

$(document).ready(function(){
/***********************************************************/

	/******* Settings *******/
	
	var speed = "medium";
	var type = "swing";
		
	
	/******* js-Klasse *******/
	
	$("a.js").click(function(evt){
		$(this).removeAttr("href");
		evt.preventDefault();
	});
	
	
	/******* toggle-Klassen *******/
	
	$(".toggled").css("display", "none");
	
	$(".toggle").css("visibility", "visible")
	.css("height", "auto")
	.css("width", "auto")
	.css("cursor", "pointer")
	.attr("href", "javascript:;");
	
	$(".toggle").click(function(evt) {
		evt.preventDefault();
		var target = $(this).attr("title");
		$("" + target + "").toggle(speed, type);
	});
	
	$(".toggleT").click(function() {
		$(this).toggle(speed, type);
	});
	
	$(".toggleF").click(function() {
		$(this).fadeOut(speed, type);
	});


	/******* smooth-scroll *******/
	
	$("a[href*=#]").click(function() {
		
		// duration in ms
		var duration = speed;
		
		// easing values: swing | linear
		var easing = type;
		
		// get / set parameters
		var newHash=this.hash;
		var target=$(this.hash).offset().top;
		var oldLocation=window.location.href.replace(window.location.hash, "");
		var newLocation=this;
		
		// make sure it's the same location
		if(oldLocation+newHash==newLocation){
			// animate to target and set the hash to the window.location after the animation
			$("html:not(:animated),body:not(:animated)").animate({ scrollTop: target }, duration, easing, function() {
				
				// add new hash to the browser location
				window.location.href=newLocation;
			});
			
			// cancel default click action
			return false;
		}
	});
	
	
	/******* mailto-link *******/
	
	$("span.mail").each(function(){
		var spt = $(this);
		var at = / at /;
		var dot = / punkt /g;
		var addr = $(spt).text().replace(at,"@").replace(dot,".");
		$(spt).after('<a href="mailto:'+addr+'" title="E-Mail an '+addr+'">'+ addr +'</a>')
		.remove();
	});
	
	
	/******* title-optimizer *******/
	
	$("a").each(function(){
		if(!$(this).attr("title")){
			$(this).attr("title", $(this).text());
		}
	});


/***********************************************************/
});
