// JavaScript Document
$(document).ready( pageStart );
 
function pageStart (){

	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	$("#dummytitle").text( document.title );
	$.historyInit(pageload);
	//onClick Events auf jeden Link setzen
	addClickHandlers();
	pageTracker._trackPageview( window.location.pathname );
	//lighbox auf alle Elemente mit rel=lighbox
};

 // PageLoad function
// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		// restore ajax loaded state
		//$("base").attr("href" , 'http://www.zauberer-rautenberg.de/' );
		$("#contentsection").load(hash + " #contentsection"  , "", addClickHandlers);
		$("#bilder").load(hash + " #bilder"  , "", addClickHandlers);
		$("#dummytitle").load(hash  + " title" , "", addClickHandlers);
		pageTracker._trackPageview( hash );

//} else {
		// start page
//		$("#content").empty();
	}
}

function addClickHandlers (  ) {
	//Funktion, die den A-Elemente onclick anhängt, wird immer wiedere nach dem Laden aufgerufen
	//Ausgenommen links die target blank haben z.B. PDF Dokumente
	$("a").not("[@target]").click(onClickEvent);
	document.title = $("#dummytitle").text();
	$(function() {
		// Use this example, or...
		//$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	});
}
//function die nach jedem Klicken aufgerufen wird
function onClickEvent () {
		 //window.location.hash = $(this).attr( "href" );
		var hash = this.href;
		change( hash);
	 return false;
}

function change(hash) {
		hash = hash.replace(/^.*#/, '');
		hash = hash.replace(window.location.host, '');
		hash = hash.replace(/^http\:\/\//, '');
		// moves to a new page. 
		// pageload is called at once. 
		$.historyLoad(hash);
}


function basepath (strPath) {
	pos = strPath.lastIndexOf('/');
	return  strPath.substr(0 , pos );
}
function goToLink(str){
                    document.header.go(str);
}