var connection = null;
var display_in = "content";
var last_page = "";
var current_page = "";
var current_caller = null;
var last_caller = null;

var progressbar_html =  '<div id="progressbar">\n'
					   +'<div id="progressbar_slider"></div>\n'
					   +'<div id="progressbar_text">0 % geladen</div>\n'
					   +'</div>\n';

function showRouting(set_visible,page) {
	var routing = document.getElementById("routing");
	var routing_shadow = document.getElementById("routing_shadow");	
	try {
		if (set_visible) {
			display_in = "routing_content";
			connection.fetch_data("/pages/anfahrt_"+page+".inc",null,false);			
			routing.style.visibility = "visible";
			routing_shadow.style.visibility = "visible";
		} else {
			routing.style.visibility = "hidden";
			routing_shadow.style.visibility = "hidden";
			document.getElementById("routing_content").innerHTML = "";
		}
	} catch (e) {}
}

function showPDF(doc,title) {
	window.open(encodeURI(doc),
				title ? title : "PDF-Dokument",	
				"dependent=yes,"
			   +"height=600,"
			   +"width=400,"
			   +"location=no,"
			   +"menubar=no,"
			   +"resizable=yes,"
			   +"scrollbars=no,"
			   +"status=yes,"
			   +"toolbar=no");
}

function insertTimeStamp(text,date) {
	var year = date.getFullYear();
	var month = date.getMonth() + 1;
	month = (month < 10) ? "0"+month : month;
	var day = date.getDate();
	day = (day < 10) ? "0"+day : day;
	var hours = date.getHours();
	var minutes = date.getMinutes();
	var seconds = date.getSeconds();

	text += "\n<div id=\"timestamp\">\nletzte &Auml;nderung am ";
	text += day+"."+month+". "+year+" um "+hours+":"+minutes+"."+seconds;
	text += "\n</div>\n";
	return text;
}

function display(text,date) {
	try {
		if (!display_in) display_in = "content";
		var content = document.getElementById(display_in);

		text = insertTimeStamp(text,date);
		content.innerHTML = text;
		if ((current_caller.className == config.menu.normalClassName) || (current_caller.className == config.menu.highlightClassName)) 
		{
			try {
				last_caller.className = config.menu.normalClassName;
				last_caller.setAttribute('class',config.menu.normalClassName);
			} catch (e) {}
			highlight(current_caller,true);
		}
	} catch(e) {
		load_content(config.menu.elements[config.menu.firstElement].pagePath);	
	}
	layout();
}

function display404(text) {
	connection.fetch_data("/pages/404.inc",null,false);		
}

function progress(e) {
	var progressbar = document.getElementById("progressbar");
	if (progressbar) {
		var percentage = (e.position / e.totalSize) * 100;
		progressbar.innerHTML.replace(/0/,percentage);
		document.getElementById("progressbar_slider").style.width=percentage + "%";
	}
}

function goBack() {
	load_content(last_caller);
}
// lädt eine neue Seite, der dazugehörige Menü-Button wird gehighlightet
function load_content(caller) {
	if (caller) {
		last_caller = current_caller;
		current_caller = caller;
	}
	last_page = current_page;
	try {
		current_page = config.menu.elements[caller.id].pagePath;
	} catch(e) {
		current_page = config.pages[caller.id].pagePath;
	}

	display_in = "content";
	
	document.getElementById(display_in).innerHTML = progressbar_html;
	
	window.setTimeout("connection.fetch_data('"+current_page+"',"+null+","+false+")",100);	
}
// highlightet einen Menübutton
function highlight(elem,set_high) {
	if (set_high) {
		try {
			elem.className = config.menu.highlightClassName;
			elem.setAttribute('class',config.menu.highlightClassName);
		}catch(e){}
	} else {
		try {
			if (elem == current_caller)
				return;
			elem.className = config.menu.normalClassName;
			elem.setAttribute('class',config.menu.normalClassName);
		}catch(e){}
	}
}
// initilisiert die ajax-Schnittstelle
function ajaxinit() {
	connection = new myAJAX();

	if (!connection) {
		window.setTimeout("ajaxinit()",1000);
		return;
	}
	connection.onnot_found = display404;
	connection.onready = display;
	connection.onreadyxml = function(){};
	connection.onloadprogress = progress;

	load_content(document.getElementById(config.menu.firstElement));	
}

function make_trans(name,id) {
	var file = document.images[name].src;
	document.images[name].src = "/images/blank.gif";
	document.getElementById(id).runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+file+"', sizingMethod='image')";
	
}
function show_ie_msg() {
	alert("Sehr geehrter Besucher.\nDiese Homepage befindet sich zur Zeit noch im Aufbau. Bitte haben Sie Verst\u00e4ndnis daf\u00fcr, dass die Unterst\u00fctzung f\u00fcr \u00e4ltere Browser (Internet Explorer 6.0 und \u00e4lter) noch nicht vollst\u00e4ndig vorhanden ist.");
}
function init() {
	try {
		if (navigator.appVersion.indexOf("MSIE 6.")>-1) {
			make_trans("eule_kl","eule_kl");
			make_trans("counter_img","counter_img");
			//window.setTimeout("show_ie_msg()",500);
			
		}
	} catch(e) {alert(e.message);}
	
	layout();	

	draginit();
	
	window.setTimeout("ajaxinit()",250);
}
try {
	document.onload = function() { window.setTimeout("init()",10); };
	window.onload = function() { window.setTimeout("init()",10); };
} catch (e) {};

