var query    = new Array ();
    query[0] = new Object();
var can_I_open_the_window = true;
$(function() {
	$('a.norm-link').click(function() {
		addQuerystring( $(this) );
	});
	$('a.linked').click(function() {
		addQuerystring( $(this) );
	});
	$('a.link_color').click(function() {
		addQuerystring( $(this) );
	});
});
function addQuerystring(thiss) {
	can_I_open_the_window = false;
	var txte = "";
	for(var kwy in query[0]) {
		if(query[0][kwy].toLowerCase() == "open") {
			txte = txte + kwy + "=" + query[0][kwy] + "&";
		}
	}
	thiss.attr('href', thiss.attr('href') + "?" + txte);
}
function addAttr(que, open_close) {
	if(que.children().hasClass('title')) {
		addArray(que.children().children().attr('href'), open_close);
	}
}
function addArray(key, value) {
	if(  !(key == "" || key == null)  ) {
		query[0][key] = value;
	}
}
$(function() {
	var head_ges = ".jQuery-head";
	$(head_ges).next().hide();
	$(head_ges).click(function(event) {
		if(can_I_open_the_window == false) {return;}
		$(this).next().toggle("fast");
		var oc = "";
		if($(this).children().hasClass("pfeil-rechts")) {
			$(this).children().removeClass("pfeil-rechts");
			$(this).children().addClass("pfeil-unten");
			oc = "open";
		}
		else if($(this).children().hasClass("pfeil-unten")) {
			$(this).children().removeClass("pfeil-unten");
			$(this).children().addClass("pfeil-rechts");
			oc = "close";
		}
		else if($(this).children().hasClass("pfeil-rechts-bold")) {
			$(this).children().removeClass("pfeil-rechts-bold");
			$(this).children().addClass("pfeil-unten-bold");
			oc = "open";
		}
		else if($(this).children().hasClass("pfeil-unten-bold")) {
			$(this).children().removeClass("pfeil-unten-bold");
			$(this).children().addClass("pfeil-rechts-bold");
			oc = "close";
		}
		addAttr($(this), oc);
	});
	$(head_ges).mouseenter(function() {
		if($(this).children().hasClass("pfeil-rechts")) {
			$(this).children().removeClass("pfeil-rechts");
			$(this).children().addClass("pfeil-rechts-bold");
		}
		if($(this).children().hasClass("pfeil-unten")) {
			$(this).children().removeClass("pfeil-unten");
			$(this).children().addClass("pfeil-unten-bold");
		}
	});
	$(head_ges).mouseleave(function() {
		if($(this).children().hasClass("pfeil-rechts-bold")) {
			$(this).children().removeClass("pfeil-rechts-bold");
			$(this).children().addClass("pfeil-rechts");
		}
		if($(this).children().hasClass("pfeil-unten-bold")) {
			$(this).children().removeClass("pfeil-unten-bold");
			$(this).children().addClass("pfeil-unten");
		}
	});
});
$(function() {
	$("div.no_javascript").removeClass('no_javascript');		/*LÖSCHT ALLE CLASSEN MIT no_javascript*/
	$("#javascript_inaktiv").addClass('hidden');
	$("#menu-slide").addClass('menu-slide_javascript');
	$("#menu-slide").addClass('hidden');
	$("#ClosePfeil").addClass('pfeil-left');
	$("#ClosePfeil").removeClass('pfeil-right');
	$("#menu").addClass('menu_javascript');
	$("#menu").removeClass('menu_no_javascript');
	$("#openmenu-slide").removeClass('hidden');
	var enabled = true;
	function enable_menu () {
		enabled = true;
	}
	$("#openmenu-slide").click (function () { open_menu(); });
	$("#openmenu-slide").mouseenter (function () { open_menu(); });
	function open_menu() {
		if(!enabled) return;
		enabled = false;
		$("#openmenu-slide").hide("slide", { direction: "left" }, 250);
		setTimeout(openslide2, 300);
	}
	function openslide2 () {
		$("#menu-slide").show("slide", { direction: "left" }, 500);
		addArray("menu", "open");
		setTimeout(enable_menu, 550);
	}
	$("#menu-slide").mouseleave( function () { close_menu(); } );
	$("#CloseButton").click( function () { close_menu(); } );
	function close_menu () {
		if(!enabled) return;
		enabled = false;
		$("#menu-slide").hide("slide", { direction: "left" }, 500);
		setTimeout(closeslide2, 550);
	}
	function closeslide2 () {
		$("#openmenu-slide").show("slide", { direction: "left" }, 250);
		addArray("menu", "close");
		setTimeout(enable_menu, 300);
	}
});
$(function() {
	$(".code").before("<div style='margin-top: 10px;font-weight: bold;font-size: 17px;'>Code:</div>");
	/*BilderGalerie*/
	$("#BilderGalerie").after("<div id='BackgroundColor' class='hidden' style='background-color: #444; top: 0px; left: 0px; bottom: 0px; right: 0px; position: fixed; opacity: 0.8; padding: 5% 10% 5%;'></div>");
});
$(function() {
	URLString = document.URL;
	beginn = URLString.indexOf("?");
	if (beginn != -1) {
		querystring = URLString.substring(beginn,URLString.length);
		last = 0;
		key_c = "";
		var ray = new Array();
		ray = new Object();
		en_val = false;
		en_key = true;
		for(var i = 0; i < querystring.length; i++) {
			now = querystring.charAt(i);
			if(now == "=" && en_key) {
				en_key = false;
				en_val = true;
				if(i == 0) {
					key_c = querystring.substring(last, i);
				}
				else {
					key_c = querystring.substring(last + 1, i);
				}
				last = i;
			}
			else if( (now == "&") && en_val) {
				en_val = false;
				en_key = true;
				value = querystring.substring(last + 1, i);
				last = i;
				show_n_hide(key_c, value);
			}
			else if(i + 1 == querystring.length && en_val) {
				value = querystring.substring(last + 1, i + 1);
			}
		}
	}
	function show_n_hide(key, value) {
		if(key == "menu" && value.toLowerCase() == "open") {
			$("#openmenu-slide").hide();
			$("#menu-slide").show();
			addArray("menu", "open");

		}
		else if(value.toLowerCase() == "open") {
			var ahref = "a[href='" + key + "']";
			$(ahref).parent().parent().next().show();
			addAttr($(ahref).parent().parent(), value);
			if($(ahref).parent().hasClass("pfeil-rechts")) {
				$(ahref).parent().removeClass("pfeil-rechts");
				$(ahref).parent().addClass("pfeil-unten");
			}
			if($(ahref).parent().hasClass("pfeil-rechts-bold")) {
				$(ahref).parent().removeClass("pfeil-rechts-bold");
				$(ahref).parent().addClass("pfeil-unten-bold");
			}
		}
	}





//********************************************************************************************************************************************
//******************************************************* DATEN VERWALTUNG BEGINNT ***********************************************************
//********************************************************************************************************************************************


	var FILE_NAME = "";
	var mode = 1;
	var daten_segment_nr=-1;
	if(beginn == -1) {
		beginn=URLString.length;
	}
	for(var dec = beginn; dec > 0; dec--) {
		if(mode == 1 && document.URL.substring(dec, dec+1) == ".") {
			mode = 2;
		}
		if(mode == 2) {
			var tmp = document.URL.substring(dec - 1, dec);
			if(tmp != "/") {
				FILE_NAME = tmp + FILE_NAME;
			} else {
				mode=0;
			}
		}
	}
	//Jetzt haben wir den Namen des Files ohne Endung.
	for(var inc = 0; inc < data_url.length; inc++) {
		if(data_url[inc]['URL'] == FILE_NAME) {
			daten_segment_nr = inc;
		}
	}
	// Jetzt haben wir die "daten_segment_nr" die uns Zugang zu den Daten gibt


	if(daten_segment_nr != -1) {
		// Jetzt muss die Position decodiert und ausgegeben werden
		var orte_array = new Array();
		var orte_array_counter = 0;
		orte_array[0] = "";
		for(var ort = 0; ort < data_url[daten_segment_nr]['POS'].length; ort++) {
			if(data_url[daten_segment_nr]['POS'].substring(ort, ort+1) == '/') {
				//Slash ignorieren und nr das Folgende Zeichen ausgeben
				ort++;
				orte_array[orte_array_counter] = orte_array[orte_array_counter] + data_url[daten_segment_nr]['POS'].substring(ort, ort+1);
				ort++;
			}
			if(data_url[daten_segment_nr]['POS'].substring(ort, ort+1) == '&') {
				orte_array_counter++;
				orte_array[orte_array_counter] = "";
			} else {
				orte_array[orte_array_counter] = orte_array[orte_array_counter] + data_url[daten_segment_nr]['POS'].substring(ort, ort+1);
			}
		}
		var topper_counter = 0
		for(var top = 0; top < orte_array.length; top++) {
			var index_zahl = -1;
			for(var inc = 0; inc < data_url.length; inc++) {
				if(data_url[inc]['URL'] == orte_array[top]) {
					index_zahl = inc;
				}
			}
			if (index_zahl != -1) {
				topper_counter++;
				$('#topper' + topper_counter).append(data_url[index_zahl]['NAME']);
				$('#topper' + topper_counter).attr('href',orte_array[top] + '.html');
			}
			if (top < orte_array.length-1) {
				$('#topper' + topper_counter).after('&nbsp;|&nbsp;');
			}
		}
	}
});
function mergesort(list) {
	var k;
	k = Math.floor(list.length/2);
	if (k < 1) {
		return;
	}
	var left = new Array();
	var right = new Array();
	while (list.length>k) {
		left.push(list.shift());
	}
	while (list.length>0) {
		right.push(list.shift());
	}
	mergesort(left);
	mergesort(right);
	while ((left.length > 0) && (right.length > 0)) {
		if (left[0] < right[0]) {
			list.push(left.shift());
		}
		else {
			list.push(right.shift());
		}
	}
	while (left.length > 0) {
		list.push(left.shift());
	}
	while (right.length > 0) {
		list.push(right.shift());
	}
	return;
}

