var zustand = location.hash;


if(location.hash) {
		x = location.hash.slice(1);
		
		//getContent(+".html");
		//alert(x);
		getContent(x+"?&type=101");
		
	}

function makeLinks(){

	//Onclick-events auf die speziellen h1 legen
	$('#c10 h1').click(function(event){
				//alert(.text());
				//$(this).children().css("display", "none");
				$(this).parent().children("ul").slideToggle("slow");
				//$('li').slideToggle("slow");
			});
			
	
	$("a").unbind("click");
	
	
	//WŠhle alle a Elemente, welche kein http:// im link haben und ziehe davon alle Elemente der Klasse "file" ab
	$("a:not([href^='http://'])").not(document.getElementsByClassName("file")).not(document.getElementsByClassName("mailto")).click(function() {
	
	//$("#navigation a").click(function() {
		url = $(this).attr("href");
                _gaq.push(['_trackPageview', url]);
                //pageTracker._trackPageview(url);
		getContent(url);
		$(this).blur();
		return false;
	});
	
	/*
	$("#subnavigation a").click(function() {
		url = $(this).attr("href");
		getContent(url);
		$(this).blur();
		return false;
	});
	
	$("#subsubnavigation a").click(function() {
		url = $(this).attr("href");
		getContent(url);
		$(this).blur();
		return false;
	});
	
	$("#clickpath a").click(function() {
		url = $(this).attr("href");
		getContent(url);
		$(this).blur();
		return false;
	}); */
	
	//Das muss jedesmal aufgerufen werden, da das div sitemap nicht
	//Ÿberschrieben wird und sonst bei jeder Ajax-Aktion ein click-event 
	//hinzugefŸgt wird.
	//Bei fŸnf Ajax-Events wird die Funktioni 5 mal ausgefŸhrt und entsprechend
	//die Seite 5 mal neu geladen
	
	$("#right_bar_head a").unbind("click");
	$("#right_bar_head a").click(function() {
		
		url = $(this).attr("href");
		getContent(url);
		
		$("#main_content").text("")
		$("#main_content").addClass("loading");
		$(this).blur();
		$("#right_bar_head a").unbind("click");
		return false;
		
		
	});
	

	//Informieren das etwas passiert
	
	
}
$("#main_content").ajaxStart(function() {
		$(this).fadeOut(function() {
			
			$(this)
				.text("")
				.addClass("loading")
				.fadeIn();
		});
		$("a").unbind("click");
	});
	
	
	
$(document).ready(function() {
	makeLinks();
	noSpam();
	
	window.setInterval(function() {
   	if (zustand != location.hash) {
      getContent(location.hash.slice(1));
   	}
	}, 500)
	

});

/*
 *	Holt den Inhalt vom Server
 */
function getContent(url) {
			
	$("#main_content").text("")
	$("#main_content").addClass("loading");
	
	$.ajax({
		//erweitere aufzurufenden Link
		url: url+"?type=101",
		//url: url.replace(/\.html/, "/ajax.html"),
		//wenn es geklappt hat
		
		//html: 
		
		success: function(html) {
			//Inhalt reinschreiben und anzeigen
			//alert("Hallo");
			//alert(content);
			//alert("HTML: "+html);
			var main_content = html.match(/<main_content>((\s|.)*?)<\/main_content>/);
			//alert("MainContent: "+main_content[1]);
			
			$("#main_content")
				.removeClass("loading")
				.css("display", "none")
				.html(main_content[1])
				.fadeIn()
			
			var navigation = html.match(/<navigation>(.*)<\/navigation>/);
			//alert(navigation[1]);
			
			$("#navigation")
				.html(navigation[1])
			
			var subnavigation = html.match(/<subnavigation>(.*)<\/subnavigation/);	
			$("#subnavigation")
				.css("display", "none")
				.html(subnavigation[1])
				.fadeIn()
				
			var clickpath = html.match(/<clickpath>(.*)<\/clickpath/);
			$("#clickpath")
				.css("display", "none")
				.html(clickpath[1])	
				.fadeIn()
				
			$("#sitemap")
				.fadeIn()
				
			//Adresszeile aktualisieren
			location.hash = url;
			
			//Hier kšnnte noch etwas verbessert werden
			zustand = location.hash;
			
			var title = html.match(/<title>(.*)<\/title>/);
			document.title = title[1];
			makeLinks();
			noSpam();		 
			
		}
		
	}
	
	);
}

//Test
		
//var html = "1. p \n 2.p \n 3.p!<title>Inhalt</title>\n4.p\n5.p";
		
		
		
		
		//html = html.replace(/.*|\s*<title>(.*)<\/title>.*/, '$1');
		//alert(html);		

var html = "\n<main_content>sdfsd</main_content>dsf";
var main_content = html.match(/<main_content>(.*)<\/main_content>/);

//alert(main_content[1]);
		
		

function chkFormular () {
  if (document.Formular.namevorname.value == "") {
    alert("Bitte Ihren Namen/Vornamen eingeben!");
    document.Formular.namevorname.focus();
    return false;
  }
  if (document.Formular.ort.value == "") {
    alert("Bitte geben Sie Ihren Ort ein!");
    document.Formular.ort.focus();
    return false;
  }
  if (document.Formular.email.value == "") {
    alert("Bitte Ihre E-Mail-Adresse eingeben!");
    document.Formular.email.focus();
    return false;
  }
    if (document.Formular.telefon.value == "") {
    alert("Bitte Ihre Telefon-Nummer eingeben!");
    document.Formular.telefon.focus();
    return false;
  }
	if (document.Formular.strasse.value == "") {
    alert("Bitte Ihre Strasse eingeben!");
    document.Formular.strasse.focus();
    return false;
  }
  if (document.Formular.email.value.indexOf("@") == -1) {
    alert("Ihre eMail-Adresse ist nicht korrekt!");
    document.Formular.email.focus();
    return false;
  }
 
  return true;
}

function noSpam() {	
    var a = document.getElementsByTagName("a");	
	for (var i = a.length-1; i >= 0; i--) {
      if (a[i].className.search(/\bcryptmail\b/) != -1) {

        var email = a[i].firstChild.data + "<del></del>@<ins></ins>" + a[i].lastChild.data;
        a[i].innerHTML = email;
        //a[i].href = "mailto:" + email;
      }
    }
  }


		
