var show_color = "#000000";
var hide_color = "#cccccc";

$(document).ready(function() {
	$(window).scroll(function() {
		var legende = $("#termin_legenden");
		if (window.pageYOffset > 150)	legende.css("top", (window.pageYOffset + 30)+"px");
	});

	$("a.cluetip").cluetip({
		arrows: true,
		ajaxCache: false
		
	});

	jQuery.each(possibleTermine, function() {
		termin = Math.abs(this);
		if (show_all) {
			$("#cat_"+termin).css("color", show_color)
		} else {
			if (jQuery.inArray(termin, showTermine) == -1) {
				$("#cat_"+termin).css("color", hide_color);
			} else {
				$("#cat_"+termin).css("color", show_color);
				
			}
		}
	});

	$(".termin_legende").css("cursor", "pointer").click(function() {
		var id = $(this).attr("id");
		id = Math.abs(id.substr(id.indexOf("_")+1));
		if (show_all) {
				$(this).css("color", show_color);
				showTermine = [id];
		} else {
			if (jQuery.inArray(id, showTermine) == -1) { // -1 == NOT FOUND
				// Nicht gefunden als zu zeigend - in Show einbauen und Schwarz malen
				$(this).css("color", show_color);
				showTermine.push(id);
			} else {
				// Gefunden - ausblenden und aus liste entfernen
				$(this).css("color", hide_color);
				showTermine = jQuery.grep(showTermine, function (a) {return Math.abs(a) != Math.abs(id)});
				if (showTermine.length == 0) showTermine = possibleTermine;
			}
		}
		document.forms[0].show.value = showTermine;
		submitIt();
	});

	$("#select_monat,#select_jahr").change(function() {
		submitIt();
	});

});

function showAll() {
	document.forms[0].show.value = possibleTermine;
	document.forms[0].search.value="Stichwort";
	submitIt();
}

function submitIt() {
	document.getElementById("submit_button").click();
}
