var historyManager = {
	
	analyticTrackCode:"",
	pageTracker:null,
	firstPage:"start.php",
	loaderID:"page-loader",
	request:null,
	isGalleryOpen:false,
	$currentSub:null,
	
	init:function () {
		try {historyManager.pageTracker = _gat._getTracker(historyManager.analyticTrackCode);} catch(e){};
		//$.ajaxSetup({error:this.onError});
		SWFAddress.onChange = this.onChange;
	},
	
	onChange:function () {
		historyManager.resetRequest();
		try {onContentClose()}catch(e){}
		var newPath = SWFAddress.getPathNames();
		if (newPath == "") newPath = historyManager.firstPage;
		
		
		try {historyManager.pageTracker._trackPageview("/"+newPath);}catch(e){};
		var parameters = '';
		if (SWFAddress.getParameterNames()) {
			for (var i = 0; i < SWFAddress.getParameterNames().length; i++) {
				parameters += '&' + SWFAddress.getParameterNames()[i] + '=' +SWFAddress.getParameter(SWFAddress.getParameterNames()[i]);
			}
		}
		
		
		$('#'+historyManager.loaderID).html ('<center><img style="margin-top:20px;margin-bottom:20px;" src="images/loader.gif" /></center>');
		historyManager.request = $.get (newPath,parameters,function (data) {
																$('#'+historyManager.loaderID).html (data);
																try {onContentDisplay()}catch(e){}
																historyManager.request = null;
																
															});	
	},
	
	
		
	openPage:function (newPage) {
		this.resetRequest();
		window.location.hash = newPage;
	},
	
	
	
	resetRequest:function () {
		if (this.request) {
			this.request.abort();
			request = null;
		}
	},
	
	
	
	
	getNewPath:function (extension) {
		var newPath = SWFAddress.getPathNames();
		if (newPath == "") newPath = historyManager.firstPage;
		if (!extension) {
			newPath = newPath.toString();
			newPath = newPath.split('.php')[0];
		}	
		return newPath;
	},
	
	
	
	
	
	onError:function (x,e) {
		if(x.status==0){
			$('#'+historyManager.loaderID).html ("Es konnte keine Verbindung hergestllt werden.");
		}else if(x.status==404){
			$('#'+historyManager.loaderID).html ("Die angeforderte Seite konnte nicht gefunden werden.");
		}else if(x.status==500){
			$('#'+historyManager.loaderID).html ("Interne Server Fehler. Bitte versuchen Sie es erneut.");
		}else if(e=='parsererror'){
			alert('Error.\nParsing JSON Request failed.');
		}else if(e=='timeout'){
			$('#'+historyManager.loaderID).html ("Zeitüberschreitung für Ihre Anfrage.");
		}else {
			alert('Unknow Error.\n'+x.responseText);
		}
	},
	
	
	
	
	
	openGallery:function () {
		historyManager.isGalleryOpen = true;
	},
	
	
	
	
	closeGallery:function () {
		historyManager.isGalleryOpen = false;
	},
	
	
	
	openSub: function (id) {
		
		if (historyManager.$currentSub)
			historyManager.$currentSub.slideUp('fast');
			
		historyManager.$currentSub = $('#'+id);
		historyManager.$currentSub.slideDown('fast');
		
	},
	
	
	closeSub: function () {
		if (historyManager.$currentSub)
			historyManager.$currentSub.slideUp('fast');
			
		historyManager.$currentSub = null;
	}




}
	
	
	
	

$(document).ready (function () {	
		historyManager.init();
		
		$('#facebook-status-container')
		.hover (	
			function () {
				$(this).stop().animate({'margin-top':0},300);
			}, 
			function () {
				$(this).stop().animate({'margin-top':-$('#facebook-status-innser').height()-10},300);
			});		
		
		
	});



