
	// 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) {
		// alert("pageload: " + hash);
		// hash doesn't contain the first # character.

		if(hash) {
			var navItem = hash.split('.')[0];
			
			// restore ajax loaded state
			if($.browser.msie) {
				// jquery's $.load() function does't work when hash include special characters like aao.
				hash = encodeURIComponent(hash);
			}
			$("#content").load(hash, initContent);
			$('body').removeClass().addClass('page-' + navItem);
			setActiveNav(navItem);
		} else {
			// start page
			$("#content").empty().load('home.html', initContent);
			$('body').removeClass().addClass('page-home');
			setActiveNav();
		}
	}
	
	function setActiveNav(navItem) {
		$('#navigation li').removeClass();
		$('#navigation li[id="nav-' + navItem + '"]').addClass('active');
		Cufon.refresh('#navigation a');	
	}
	
	function initContent() {
		$("#content div#imageGallery a").fancybox({titleShow: false});
	};
	
	$(document).ready(function() {
		// Raute Zeichen im Link einfügen (für History Management)
		$("#navigation li a, a[rel='history']").each(function() {
			var linkParts = this.href.split('/');
			var linkMax = linkParts.length - 1;
			var newLinkEnd = '#' + linkParts[linkMax];

			this.href = this.href.replace(linkParts[linkMax], newLinkEnd);	
		});

		// Schriften ersetzen
		Cufon.replace('#navigation a', {hover: true});					   
		Cufon.replace('#barInfo');

	
		// Flash Button initialisieren
		/*$('#wmbutton').flash({
			swf: 'wmbutton.swf',
			wmode: 'transparent',
			width: 240,
			height: 240
		});

		// custom options
		$("#wmsong").jmp3({
			filepath: 'music/',
			autoplay: true,
			showfilename: false
		});*/

		// Initialize history plugin.
		// The callback is called at once by present location.hash. 
		$.historyInit(pageload, "home.html");

		if(window.location.href.search('#') == -1) {
			$('body').removeClass().addClass('page-home');
			$("#content").load('home.html', initContent);
		}
		// set onlick event for buttons
		$("#navigation li a, a[rel='history']").click(function(){
			var hash = this.href;
			hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			// hash don't contain "#", "?"
			$.historyLoad(hash);
			return false;
		});
	});
