$(function() {
	$(window).load(function() { 
		$("#ergotherapieMenu .inner").stop().css("top", "-120px");
		$("#tiertherapieMenu .inner").stop().css("top", "-120px");
		$("#erlebnispaedagogikMenu .inner").stop().css("top", "-120px");
		
		$("#ergotherapieMenu").stop().css("display", "inherit");
		$("#tiertherapieMenu").stop().css("display", "inherit");
		$("#erlebnispaedagogikMenu").stop().css("display", "inherit");
		
		$("#ergotherapieMenu").stop().css("visibility", "hidden");
		$("#tiertherapieMenu").stop().css("visibility", "hidden");
		$("#erlebnispaedagogikMenu").stop().css("visibility", "hidden");
		
		if($("#Ergotherapie").hasClass("active")) $("#Ergotherapie").css("background-position", "0 0");
		if($("#Tiertherapie").hasClass("active")) $("#Tiertherapie").css("background-position", "0 0");
		if($("#Erlebnispaedagogik").hasClass("active")) $("#Erlebnispaedagogik").css("background-position", "0 0");
	});
	 
	var ergoOver = false;
	var ergoTimer;
	var tierOver = false;
	var tierTimer;
	var paedaOver = false;
	var paedaTimer;
	
	$("#Ergotherapie").mouseover(
		function () {
			$("#Ergotherapie").css("background-position", "0 0");
			$("#ergotherapieMenu").stop().css("visibility", "visible");
			if(ergoOver){
				$("#ergotherapieMenu .inner").stop().css("top", "0");
			}
			else{
				$("#ergotherapieMenu .inner").stop().animate({top: 0}, 500);
			}
			ergoOver = true;
			clearTimeout(ergoTimer);
		}
	).mouseout(
		function () {
			if(! $("#Ergotherapie").hasClass("active") ) $("#Ergotherapie").css("background-position", "0 -43px");
			$("#ergotherapieMenu .inner").stop().css("top", "-120px");
			$("#ergotherapieMenu").stop().css("visibility", "hidden");
			ergoTimer = setTimeout (function() {ergoOver = false;}, 250); 
		}
	);
	
	$("#Tiertherapie").mouseover(
		function () {
			$("#Tiertherapie").css("background-position", "0 0");
			$("#tiertherapieMenu").stop().css("visibility", "visible");
			if(tierOver){
				$("#tiertherapieMenu .inner").stop().css("top", "0");
			}
			else{
				$("#tiertherapieMenu .inner").stop().animate({top: 0}, 500);
			}
			tierOver = true;
			clearTimeout(tierTimer);
		}
	).mouseout(
		function () {
			if(! $("#Tiertherapie").hasClass("active")) $("#Tiertherapie").css("background-position", "0 -43px");
			$("#tiertherapieMenu .inner").stop().css("top", "-120px");
			$("#tiertherapieMenu").stop().css("visibility", "hidden");
			tierTimer = setTimeout (function() {tierOver = false;}, 250); 
		}
	);
	
	$("#Erlebnispaedagogik").mouseover(
		function () {
			$("#Erlebnispaedagogik").css("background-position", "0 0");
			$("#erlebnispaedagogikMenu").stop().css("visibility", "visible");
			if(paedaOver){
				$("#erlebnispaedagogikMenu .inner").stop().css("top", "0");
			}
			else{
				$("#erlebnispaedagogikMenu .inner").stop().animate({top: 0}, 500);
			}
			paedaOver = true;
			clearTimeout(paedaTimer);
		}
	).mouseout(
		function () {
			if(!$("#Erlebnispaedagogik").hasClass("active")) $("#Erlebnispaedagogik").css("background-position", "0 -43px");
			$("#erlebnispaedagogikMenu .inner").stop().css("top", "-120px");
			$("#erlebnispaedagogikMenu").stop().css("visibility", "hidden");
			paedaTimer = setTimeout (function() {paedaOver = false;}, 250); 
		}
	);
	
	$("#ergotherapieMenu .inner").mouseover(
		function () {
			$("#ergotherapieMenu .inner").stop().css("top", "0");
			$("#Ergotherapie").css("background-position", "0 0");
			$("#ergotherapieMenu").stop().css("visibility", "visible");
			ergoOver = true;
			clearTimeout(ergoTimer);
		}
	).mouseout(
		function () {
			if(! $("#Ergotherapie").hasClass("active")) $("#Ergotherapie").css("background-position", "0 -43px");
			$("#ergotherapieMenu .inner").stop().css("top", "-120px");
			$("#ergotherapieMenu").stop().css("visibility", "hidden");
			ergoTimer = setTimeout (function() {ergoOver = false;} ,100); 
		}
	);
	
	$("#tiertherapieMenu .inner").mouseover(
		function () {
			$("#tiertherapieMenu .inner").stop().css("top", "0");
			$("#Tiertherapie").css("background-position", "0 0");
			$("#tiertherapieMenu").stop().css("visibility", "visible");
			tierOver = true;
			clearTimeout(tierTimer);
		}
	).mouseout(
		function () {
			if(! $("#Tiertherapie").hasClass("active")) $("#Tiertherapie").css("background-position", "0 -43px");
			$("#tiertherapieMenu .inner").stop().css("top", "-120px");
			$("#tiertherapieMenu").stop().css("visibility", "hidden");
			tierTimer = setTimeout (function() {tierOver = false;} ,100); 
		}
	);
	
	$("#erlebnispaedagogikMenu .inner").mouseover(
		function () {
			$("#erlebnispaedagogikMenu .inner").stop().css("top", "0");
			$("#Erlebnispaedagogik").css("background-position", "0 0");
			$("#erlebnispaedagogikMenu").stop().css("visibility", "visible");
			paedaOver = true;
			clearTimeout(paedaTimer);
		}
	).mouseout(
		function () {
			if(!$("#Erlebnispaedagogik").hasClass("active")) $("#Erlebnispaedagogik").css("background-position", "0 -43px");
			$("#erlebnispaedagogikMenu .inner").stop().css("top", "-120px");
			$("#erlebnispaedagogikMenu").stop().css("visibility", "hidden");
			paedaTimer = setTimeout (function() {paedaOver = false;} ,100); 
		}
	);
});
