var actualNavPoint = "";

$(document).ready(function(){

	$("ul.level_1").children("li").each(function(){
		$(this).hover(function(){
			$submenu = $(this).children("ul.level_2");

			if($(this).children("div").children("a").html() != actualNavPoint)
			{
				//alert(actualNavPoint+"---"+$(this).children("div").children("a").html())
				handleHide();
				actualNavPoint = $(this).children("div").children("a").html();
				$(this).children("div").children("span").css("backgroundColor", "#5d5e60");
			}

			if($submenu.length > 0)
			{
				$(this).css("zIndex", 1000);

				$submenu.hover(function(){

					stopHideSubs();

				})



				$(this).children("div").children("a").addClass("hovered");
				$submenu.css("left", "-0px");

				//$submenu.css("left", $(this).offset().left - $("#wrapper").offset().left);
			   	$(this).children("ul.level_2").show();
			}
		})
	})



	$("ul.level_2 li").hover(function(){
		stopHideSubs();
	})

	$("#container").hover(function(){
		handleHide();
	})

	$(".mod_changelanguage").hover(function(){
		handleHide();
	});


	$(".mod_navigation").hover(function(){
		handleHide()
	});


	$(".subtext").each(function(){
		$(this).hide();
	})

	$("h3.subhead").each(function(){
		$(this).hide();
	})

	$("#beraterteam").click(function(){
		initHomeAni()
	})

	$("h2.subhead").click(function(){
		p = $(this).next().next("div").html();

		h1 = $("<h1>");
		h2 = $("<h2>");

		h1.html($(this).html());
		h2.html($(this).next("h3").html());

		body = $("<div>");
		body.append(h1);
		body.append(h2);
		body.append(p);

		if($("#LayerContent").html() == null)
		{
			$("#Layer").append('<div id="LayerContent"></div>');
		}

		//alert($("#Layer").html());

		$("#LayerContent").html(body.html());
		showLayer();
	})

	$("h2.conhead a").click(function(e){
		e.preventDefault();
	})


	$("h2.conhead").click(function(){


//240x333

		h1 = $("<h1>");
		h2 = $("<h2>");
		p = $("<p>");
		img = $("<img>");

		span = $("<span>");

		h1.html($(this).children(".name").html());
		h2.html($(this).children(".profession").html());
		p.html($(this).next("div").children(".text").html());
		p.css("width", 275);
		p.css("line-height","21px");
		p.css("margin-top","15px");
		p.css("text-align", "justify");

		if($("#LayerContent").html() == null)
		{
			$("#Layer").append('<div id="LayerContent"></div>');
		}

		img.attr("src", $(this).next("div").children("img").attr("src"));

		img.css({
			position: "absolute",
			right: "85px",
			top: "75px"
		});

		span.css({
			"position": "absolute",
			"left": "85px",
			"bottom": "25px",
			"width": 200
		});
		span.html($(this).children(".email").html())
		span.children("a").css("color", "red");
		span.children("a").css("fontWeight", "bold");

		body = $("<div>");
		body.append(h1);
		body.append(h2);
		body.append(p);
		body.append(img);
		body.append(span);
//		alert(body.html());

//		alert(body.html());
		$("#LayerContent").html(body.html());
//		alert($("#LayerContent").html());
		showLayer();

	})

	$("body").append('<div id="LayerBg"></div><div id="Layer"><a id="Close" href="javascript:;" onclick="hideLayer();"><img src="/tl_files/images/close.png"> schließen/close</a><div id="LayerContent>aaa</div></div>');

	hideLayer();

})

var hideTimer;

function hideLayer()
{
	$("#LayerBg").hide();
	$("#Layer").hide();
}

function showLayer()
{
	$("#LayerBg").show();
	$("#Layer").show();
}

function hideSubs()
{
	return;
	hideTimer = setTimeout("handleHide()", 300);
}

function stopHideSubs()
{
	clearTimeout(hideTimer);
}

function handleHide()
{
	$("ul.level_1 li .square").each(function(){
		$(this).css("backgroundColor", "#fff");
	})
	$("*").removeClass("hovered");
	$("ul.level_2").each(function(){

		$(this).hide();

	})

}

function initHomeAni(){

	$("#beraterteam > div > img").animate({
	    opacity: 0.25,
	    width:'320px',
	    height:'166px'
	  }, 500, function() {
	    $("#starttext").fadeIn(500);
	  });


}

$(window).load(function(){

	setTimeout("initHomeAni()", 2500);

})
