// JavaScript Document

var navPath = "/_media/images/navigation/main/";
var subPath = "/_media/images/navigation/sub/";
var headingPath = "/_media/images/heading/";

$(function() {
    $('a[rel=popup]').click(function(){
        window.open($(this).attr('href'),'','width=500');
        return false;
    });
    $('a[rel=_blank]').click(function(){
        window.open($(this).attr('href'));
        return false;
    });

	/*$('div:not(#sidebar-left) .rendered a').each(function() {
		var a = $(this);
		a.t = normalize(a.text());
		a.css('background-image','url('+ navPath + a.t +'.gif)');
	})

	$('div:not(#sidebar-left) .rendered a').each(function() {
		var a = $(this);
		a.t = normalize(a.text());
		var x = $('<img src="'+ navPath + a.t +'.gif" alt="'+a.text()+'">');
		a.text('');
		a.prepend(x);
	})*/

	$('#content > h1:first').each(function() {
		var b = $(this);
		b.t = normalize(b.text());
		var y = $('<img src="'+ headingPath + b.t +'.gif" alt="'+b.text()+'">');
		b.text('');
		b.prepend(y);
	})

	$('#sidebar-left .render-navi a').each(function() {
		var c = $(this);
		c.t = normalize(c.text());
		c.css('background-image','url('+ subPath + c.t +'.gif)');
	})

	$('#content a.link)').prepend("&gt; ");
	$('#footer li:not(.last) a').append(" |");

	// Popup Menus ausblenden, wenn Javascript aktiv ist:
	$('#sidebar-left ul li ul').addClass("jsmenu");
	$('#sidebar-left ul li ul').hide();

	$('#sidebar-left ul:first li').hover(
      function () {
        $(this).find('ul:first').show(); //this > ul?
      },
      function () {
        $(this).find('ul:first').hide();
      }
    );

	//Galerie-Popups unter Kontakt
	$('.bilder a').lightBox();


});

function normalize(a) {
    a = a.toLowerCase();
    a = a.replace(/ /g,'_');
    a = a.replace(/\//g,'-');
	a = a.replace(/\./g,'');
    a = a.replace(/\)/g,'');
    a = a.replace(/\(/g,'');
	a = a.replace(/,/g,'');
    a = a.replace(/ä/g,'ae');
    a = a.replace(/ü/g,'ue');
    a = a.replace(/ö/g,'oe');
    a = a.replace(/ß/g,'ss');
    return a;
}