$(document).ready( function() {
	var	currentPath = $(location).attr('href');
	var slices = currentPath.split("/");
	var lastitem = slices.length-1;
	var currentPage = "";
	if(lastitem>3) currentPage = slices[lastitem-1] +"/"+ slices[lastitem];
	else currentPage = slices[lastitem];	
	
	//Alle Navipunkte mit Unterpunkten sind automatisch aktiv	
	$('#navi li ul').parent().addClass('active');
	
	//Oder wenn Seitenname und href gelcih sind aktiv setzen
	$('li a').each(function(index){
		if(currentPage!=""){
			if($(this).attr('href').indexOf("/"+currentPage)!=-1) $(this).parent().addClass('active');
		}
	});
		
	//email spam protection - Example Markup: <span class="email">name[at]domain[dot]com</span>
    $('.email').each(function() {
        var $email = $(this);
        var address = $email.text()
        .replace(/\s*\[at\]\s*/, '@')
        .replace(/\s*\[dot\]\s*/g, '.');
        $email.html('<a href="mailto:' + address + '">'+ address +'</a>');
    });
	
	
	//Header mit Titel versehen	
	var titel = "";	
	titel = $('li.active a').first().text();	
	if (titel=="") titel="Home";
	var headerImg = $('<img alt="'+titel+'" />').hide().bind('load', function(){$(this).fadeIn();});
	$('#header').append(headerImg);
	headerImg.attr('src', "/images/header/"+titel+".jpg");
	
});
