
function subsAnimBack(sub)
{
	$("#sub5").stop().animate({height: "100px"}, "slow");
	$("#sub4").stop().animate({height: "200px"}, "slow");
	$("#sub3").stop().animate({height: "300px"}, "slow");
	$("#sub2").stop().animate({height: "400px"}, "slow");
	$("#sub1").stop().animate({height: "500px"}, "slow");
	$(".sub_bg").stop().animate({opacity: 0}, "slow");
	$(".sub_desc").stop().animate({"padding-top": "500px"}, "slow");
	$(".sub_headline_bg2").stop().animate({opacity: 0}, "slow");

	if ((document.location.href.indexOf("ueber_uns") != -1 || document.location.href.indexOf("referenzen") != -1 || document.location.href.indexOf("leistungen") != -1) && !($.browser.msie && $.browser.version=="6.0"))
	{
		$("#hovercontent").each(function () {
			if (sub.find(".sub_desc").html() == $(this).html())
				$(this).stop().fadeTo("slow", 0, function () {$(this).css({"display": "none"})});
		});
		$("#main_fader").stop().fadeTo("slow", 0, function () {
			$(this).css({"display": "none"})
			$("#hovercontent").each(function () {
				if ($(this).css("opacity") > 0)
					$(this).stop().fadeTo("slow", 0, function () {$(this).css({"display": "none"})});
			});
		});
		$(".sub_more").stop().animate({"padding-top": "500px"}, "slow");
	}
}

$(window).load(function()
{
	/*
	 * INIT
	 */
	$(".sub_bg").stop().css({display: "block", opacit: 0});
	$("#submenu_wrapper p").stop().css({display: "block", opacit: 0});
	$(".sub_fade").stop().css({display: "block"});
	$("#hovercontent").hide().css({"opacity": 0});
	$("#main_fader").css({"opacity": 0});
	(function ($) {
	$.fn.vAlign = function() {
		return this.each(function(i){
			var h = $(this).height();
			var oh = 500 - 5*41;
			var mt = oh-h;
			$(this).css({"padding-top": mt + "px"});
		});	
	};
	})(jQuery);
	(function ($) {
	$.fn.vAlignAnimate = function() {
		return this.each(function(i){
			var h = $(this).height();
			var oh = 500 - 5*41;
			var mt = oh-h;
			$(this).stop().animate({"padding-top": mt + "px"}, "slow");
		});	
	};
	})(jQuery);
	if (document.location.href.indexOf("referenzen") != -1)
	{
		$("#submenu_wrapper p").css({"font-size": "13px", "width": "280px"});
		$(".sub_headline").children().each(function () {
			$(this).replaceWith(this.childNodes);
		});
	}
	$("#sub1").each(function (i) {
		if ($(this).find(".sub_headline").html() != "Luft" && $(this).find(".sub_headline").find("a").attr("href"))
		{
			$(this).css({"cursor": "pointer"});
			$(this).click(function () { document.location.href = $(this).find(".sub_headline").find("a").attr("href"); });
		}
	});
	$("#sub2").each(function (i) {
		if ($(this).find(".sub_headline").html() != "Erde" && $(this).find(".sub_headline").find("a").attr("href"))
		{
			$(this).css({"cursor": "pointer"});
			$(this).click(function () { document.location.href = $(this).find(".sub_headline").find("a").attr("href"); });
		}
	});
	$("#sub3").each(function (i) {
		if ($(this).find(".sub_headline").html() != "Mensch" && $(this).find(".sub_headline").find("a").attr("href"))
		{
			$(this).css({"cursor": "pointer"});
			$(this).click(function () { document.location.href = $(this).find(".sub_headline").find("a").attr("href"); });
		}
	});
	$("#sub4").each(function (i) {
		if ($(this).find(".sub_headline").html() != "Wasser" && $(this).find(".sub_headline").find("a").attr("href"))
		{
			$(this).css({"cursor": "pointer"});
			$(this).click(function () { document.location.href = $(this).find(".sub_headline").find("a").attr("href"); });
		}
	});
	$("#sub5").each(function (i) {
		if ($(this).find(".sub_headline").html() != "Feuer" && $(this).find(".sub_headline").find("a").attr("href"))
		{
			$(this).css({"cursor": "pointer"});
			$(this).click(function () { document.location.href = $(this).find(".sub_headline").find("a").attr("href"); });
		}
	});
	if (document.location.href.indexOf("kunde") != -1 || document.location.href.indexOf("industrie_und_gewerbe") != -1 || document.location.href.indexOf("sanitaertechnik") != -1)
	{
		$("#sub5").stop().css({height: "41px"});
		$("#sub4").stop().css({height: "82px"});
		$("#sub3").stop().css({height: "123px"});
		$("#sub2").stop().css({height: "164px"});
		$("#sub1").stop().css({height: "500px"});
		$("#sub1 .sub_bg").stop().css({opacity: 1});
		$("#sub1 .sub_desc").css({"visibility" : "hidden"});

		if (document.location.href.indexOf("referenzen") != -1)
			$("#sub1 .sub_desc").stop().css({"visibility" : "visible"}).vAlign();
	}
	if (document.location.href.indexOf("team") != -1 || document.location.href.indexOf("verwaltungsbauten") != -1 || document.location.href.indexOf("heizung") != -1)
	{
		$("#sub5").stop().css({height: "41px"});
		$("#sub4").stop().css({height: "82px"});
		$("#sub3").stop().css({height: "123px"});
		$("#sub2").stop().css({height: "459px"});
		$("#sub1").stop().css({height: "500px"});
		$("#sub2 .sub_bg").stop().css({opacity: 1});
		$("#sub2 .sub_desc").css({"visibility" : "hidden"});

		if (document.location.href.indexOf("referenzen") != -1)
			$("#sub2 .sub_desc").stop().css({"visibility" : "visible"}).vAlign();
	}
	if (document.location.href.indexOf("philosophie") != -1 || document.location.href.indexOf("freizeit_kultur_und_bildung") != -1 || document.location.href.indexOf("medienversorgung") != -1)
	{
		$("#sub5").stop().css({height: "41px"});
		$("#sub4").stop().css({height: "82px"});
		$("#sub3").stop().css({height: "418px"});
		$("#sub2").stop().css({height: "459px"});
		$("#sub1").stop().css({height: "500px"});
		$("#sub3 .sub_bg").stop().css({opacity: 1});
		$("#sub3 .sub_desc").css({"visibility" : "hidden"});

		if (document.location.href.indexOf("referenzen") != -1)
			$("#sub3 .sub_desc").stop().css({"visibility" : "visible"}).vAlign();
	}
	if (document.location.href.indexOf("qualitaetsmanagement") != -1 || document.location.href.indexOf("gesundheitsbauten") != -1 || document.location.href.indexOf("gebaeudeautomation") != -1)
	{
		$("#sub5").stop().css({height: "41px"});
		$("#sub4").stop().css({height: "377px"});
		$("#sub3").stop().css({height: "418px"});
		$("#sub2").stop().css({height: "459px"});
		$("#sub1").stop().css({height: "500px"});
		$("#sub4 .sub_bg").stop().css({opacity: 1});
		$("#sub4 .sub_desc").css({"visibility" : "hidden"});

		if (document.location.href.indexOf("referenzen") != -1)
			$("#sub4 .sub_desc").stop().css({"visibility" : "visible"}).vAlign();
	}
	if (document.location.href.indexOf("historie") != -1 || document.location.href.indexOf("sonderanlagen") != -1 || document.location.href.indexOf("dienstleistungen") != -1)
	{
		$("#sub5").stop().css({height: "336px"});
		$("#sub4").stop().css({height: "377px"});
		$("#sub3").stop().css({height: "418px"});
		$("#sub2").stop().css({height: "459px"});
		$("#sub1").stop().css({height: "500px"});
		$("#sub5 .sub_bg").stop().css({opacity: 1});
		$("#sub5 .sub_desc").css({"visibility" : "hidden"});

		if (document.location.href.indexOf("referenzen") != -1)
			$("#sub5 .sub_desc").stop().css({"visibility" : "visible"}).vAlign();
	}
	

	/*
	 * SUB 1
	 */
	$("#sub1").mouseenter(function ()
	{
		$("#sub5").stop().animate({height: "41px"}, "slow");
		$("#sub4").stop().animate({height: "82px"}, "slow");
		$("#sub3").stop().animate({height: "123px"}, "slow");
		$("#sub2").stop().animate({height: "164px"}, "slow");

		$("#sub1").stop().animate({height: "500px"}, "slow");

		$("#sub1 .sub_bg").stop().animate({opacity: 1}, "fast");
		$("#sub1 .sub_desc").stop().vAlignAnimate();

		if ((document.location.href.indexOf("ueber_uns") != -1 || document.location.href.indexOf("leistungen") != -1) && $("#sub1 .sub_bg").css("opacity") != 1 && !($.browser.msie && $.browser.version=="6.0"))
		{
			if ($("#sub1 .sub_more").length == 0)
			{
				$("#sub1 .sub_headline_content").append( $("<p>Mehr ...</p>").addClass("sub_more") );
				$("#sub1 .sub_desc").css({"visibility" : "hidden"})
			}
			$("#sub1 .sub_more").stop().vAlignAnimate();
			if ($("#hovercontent").css("opacity") > 0)
			{
				$("#hovercontent").stop().fadeTo("normal", 0, function () {
					$("#hovercontent").html($("#sub1 .sub_desc").html());
					$("#hovercontent").css({"display": "block"}).stop().fadeTo("normal", 1);
					$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
				});
			} else {
				$("#hovercontent").html($("#sub1 .sub_desc").html());
				$("#hovercontent").css({"display": "block"}).fadeTo("normal", 1);
				$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
			}
			$("#main_fader").css({"display": "block"}).stop().fadeTo("slow", 0.9);
		}
	});
	$("#sub1").mouseleave(function ()
	{
		subsAnimBack($("#sub1"));
	});

	/*
	 * SUB 2
	 */
	$("#sub2").mouseenter(function ()
	{
		$("#sub5").stop().animate({height: "41px"}, "slow");
		$("#sub4").stop().animate({height: "82px"}, "slow");
		$("#sub3").stop().animate({height: "123px"}, "slow");

		$("#sub2").stop().animate({height: "459px"}, "slow");
		$("#sub1").stop().animate({height: "500px"}, "slow");

		$("#sub2 .sub_bg").stop().animate({opacity: 1}, "fast");
		$("#sub2 .sub_desc").stop().vAlignAnimate();

		if ((document.location.href.indexOf("ueber_uns") != -1 || document.location.href.indexOf("leistungen") != -1) && $("#sub2 .sub_bg").css("opacity") != 1 && !($.browser.msie && $.browser.version=="6.0"))
		{
			if ($("#sub2 .sub_more").length == 0)
			{
				$("#sub2 .sub_headline_content").append( $("<p>Mehr ...</p>").addClass("sub_more") );
				$("#sub2 .sub_desc").css({"visibility" : "hidden"})
			}
			$("#sub2 .sub_more").stop().vAlignAnimate();
			if ($("#hovercontent").css("opacity") > 0)
			{
				$("#hovercontent").stop().fadeTo("normal", 0, function () {
					$("#hovercontent").html($("#sub2 .sub_desc").html());
					$("#hovercontent").stop().fadeTo("normal", 1);
					$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
				});
			} else {
				$("#hovercontent").html($("#sub2 .sub_desc").html());
				$("#hovercontent").fadeTo("normal", 1);
				$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
			}
			$("#main_fader").css({"display": "block"}).stop().fadeTo("slow", 0.9);
		}
	});
	$("#sub2").mouseleave(function ()
	{
		subsAnimBack($("#sub2"));
	});

	/*
	 * SUB 3
	 */
	$("#sub3").mouseenter(function ()
	{
		$("#sub5").stop().animate({height: "41px"}, "slow");
		$("#sub4").stop().animate({height: "82px"}, "slow");

		$("#sub3").stop().animate({height: "418px"}, "slow");
		$("#sub2").stop().animate({height: "459px"}, "slow");
		$("#sub1").stop().animate({height: "500px"}, "slow");

		$("#sub3 .sub_bg").stop().animate({opacity: 1}, "fast");
		$("#sub3 .sub_desc").stop().vAlignAnimate();

		if ((document.location.href.indexOf("ueber_uns") != -1 || document.location.href.indexOf("leistungen") != -1) && $("#sub3 .sub_bg").css("opacity") != 1 && !($.browser.msie && $.browser.version=="6.0"))
		{
			if ($("#sub3 .sub_more").length == 0)
			{
				$("#sub3 .sub_headline_content").append( $("<p>Mehr ...</p>").addClass("sub_more") );
				$("#sub3 .sub_desc").css({"visibility" : "hidden"})
			}
			$("#sub3 .sub_more").stop().vAlignAnimate();
			if ($("#hovercontent").css("opacity") > 0)
			{
				$("#hovercontent").stop().fadeTo("normal", 0, function () {
					$("#hovercontent").html($("#sub3 .sub_desc").html());
					$("#hovercontent").stop().fadeTo("normal", 1);
					$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
				});
			} else {
				$("#hovercontent").html($("#sub3 .sub_desc").html());
				$("#hovercontent").fadeTo("normal", 1);
				$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
			}
			$("#main_fader").css({"display": "block"}).stop().fadeTo("slow", 0.9);
		}
	});
	$("#sub3").mouseleave(function ()
	{
		subsAnimBack($("#sub3"));
	});

	/*
	 * SUB 4
	 */
	$("#sub4").mouseenter(function ()
	{
		$("#sub5").stop().animate({height: "41px"}, "slow");

		$("#sub4").stop().animate({height: "377px"}, "slow");
		$("#sub3").stop().animate({height: "418px"}, "slow");
		$("#sub2").stop().animate({height: "459px"}, "slow");
		$("#sub1").stop().animate({height: "500px"}, "slow");

		$("#sub4 .sub_bg").stop().animate({opacity: 1}, "fast");
		$("#sub4 .sub_desc").stop().vAlignAnimate();

		if ((document.location.href.indexOf("ueber_uns") != -1 || document.location.href.indexOf("leistungen") != -1) && $("#sub4 .sub_bg").css("opacity") != 1 && !($.browser.msie && $.browser.version=="6.0"))
		{
			if ($("#sub4 .sub_more").length == 0)
			{
				$("#sub4 .sub_headline_content").append( $("<p>Mehr ...</p>").addClass("sub_more") );
				$("#sub4 .sub_desc").css({"visibility" : "hidden"})
			}
			$("#sub4 .sub_more").stop().vAlignAnimate();
			if ($("#hovercontent").css("opacity") > 0)
			{
				$("#hovercontent").stop().fadeTo("normal", 0, function () {
					$("#hovercontent").html($("#sub4 .sub_desc").html());
					$("#hovercontent").stop().fadeTo("normal", 1);
					$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
				});
			} else {
				$("#hovercontent").html($("#sub4 .sub_desc").html());
				$("#hovercontent").fadeTo("normal", 1);
				$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
			}
			$("#main_fader").css({"display": "block"}).stop().fadeTo("slow", 0.9);
		}
	});
	$("#sub4").mouseleave(function ()
	{
		subsAnimBack($("#sub4"));
	});

	/*
	 * SUB 5
	 */
	$("#sub5").mouseenter(function ()
	{
		$("#sub5").stop().animate({height: "336px"}, "slow");
		$("#sub4").stop().animate({height: "377px"}, "slow");
		$("#sub3").stop().animate({height: "418px"}, "slow");
		$("#sub2").stop().animate({height: "459px"}, "slow");
		$("#sub1").stop().animate({height: "500px"}, "slow");

		$("#sub5 .sub_bg").stop().animate({opacity: 1}, "fast");
		$("#sub5 .sub_desc").stop().vAlignAnimate();

		if ((document.location.href.indexOf("ueber_uns") != -1 || document.location.href.indexOf("leistungen") != -1) && $("#sub5 .sub_bg").css("opacity") != 1 && !($.browser.msie && $.browser.version=="6.0"))
		{
			if ($("#sub5 .sub_more").length == 0)
			{
				$("#sub5 .sub_headline_content").append( $("<p>Mehr ...</p>").addClass("sub_more") );
				$("#sub5 .sub_desc").css({"visibility" : "hidden"})
			}
			$("#sub5 .sub_more").stop().vAlignAnimate();
			if ($("#hovercontent").css("opacity") > 0)
			{
				$("#hovercontent").stop().fadeTo("normal", 0, function () {
					$("#hovercontent").html($("#sub5 .sub_desc").html());
					$("#hovercontent").stop().fadeTo("normal", 1);
					$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
				});
			} else {
				$("#hovercontent").html($("#sub5 .sub_desc").html());
				$("#hovercontent").fadeTo("normal", 1);
				$("#hovercontent").css({"margin-top": $("#hovercontent").height()/2*-1});
			}
			$("#main_fader").css({"display": "block"}).stop().fadeTo("slow", 0.9);
		}
	});
	$("#sub5").mouseleave(function ()
	{
		subsAnimBack($("#sub5"));
	});

	/*
	 * Karte
	 */
	$(".dd").mouseenter(function () {
		var d = $("<div />").css({
			"position": "absolute",
			"top": "0",
			"left": "0",
			"width": "auto",
			"height": "auto"
		}).addClass("dhover");
		d.append($("<div />").addClass("dbg").css({"opacity": 0.8}));
		d.append($("<div />").addClass("tc"));
		d.find(".tc").append($("<span />").addClass("hl2").html($(this).find(".hl").html()));
		d.find(".tc").append($("<span />").addClass("sl2").html($(this).find(".sl").html()));
		$(this).parent().append(d);
		d.css({
			"margin-top": ($(this).css("margin-top").replace("px", "")*1) + (($(this).height()/2)-(d.height()/2)),
			"margin-left": ($(this).css("margin-left").replace("px", "")*1) + (($(this).width()/2)-(d.width()/2))
		});
		d.hide();
		$(this).stop().fadeTo("normal", 0);
		$.data(d[0], "ref", $(this));
		$.data(d[0], "hasHadMouse", false);
		d.stop().fadeTo("slow", 1, function() {
			$(this).css({"filter": ""})
			if ($.data(this, "hasHadMouse") === false)
			{
				$(this).find(".dbg").stop().fadeTo("normal", 0);
				//$.data(this, "ref").stop().css({"opacity": 0.5})
				$.data(this, "ref").stop().fadeTo("normal", 1, function() {$(this).css({"filter": ""})});
				//alert($.data(this, "ref").css("opacity"))
				$(this).stop().fadeTo("normal", 0, function () {
					$(this).remove();
				});
			}
		});
		d.find(".dbg").stop().animate({"height": d.height()+20, "margin-top": d.height()/2*-1-10}, function () {
			$(this).animate({"width": $(this).parent().width()+20, "margin-left": $(this).parent().width()/2*-1-10});
		});
		d.mouseenter(function () {
			$.data(this, "hasHadMouse", true);
		});
		d.mouseleave(function () {
			$(this).find(".dbg").stop().animate({"width": 10, "margin-left": -5, "opacity": 0});
			$.data(this, "ref").stop().fadeTo("normal", 1, function() {$(this).css({"filter": ""})});
			$(this).stop().fadeTo("normal", 0, function () {
				$(this).remove();
			});
		});
	});
});

