function initPage(){
	$("#page_margins").removeClass("hidden");
	$('div#preloader').css({display:'none'}).remove();
	/* get a flexible width for the service menupoint */
	//$("#menu li.levelOne:last .subhlist").css("width", "auto");

	//Navigationfallback --> if the User dont use js
	removeNoJSClass();
	//functions	
	changeHeaderContent();
	//newSildeNav();
	window.setTimeout("newSildeNav()", 1000);
	initMitarbeiter();
	initReferenz();
	toggleContent(); 
}

function changeHeaderContent(){
	initDynamicHeader("#testimonial");
}
function removeNoJSClass(){
	$("#menu").removeClass("noJS");
	$(".hiddenContent").removeClass("noJS");
	$("#page").find(".noJSHide").each(function(){
		$(this).removeClass("noJSHide");
	});
}

var oldTextHeight = 0;
function toggleContent(){
	//Use the animation-Funktion instead of the slideToggle beacause of the "jump-Bug"
	//Save the heights of the hidden Contents in the Value-Attribute.
	//Hide all hidden Contents an set the height-Attribute to 0. Otherwise the height-animation cant raise the Height correctly.
	$("#main .previewContainer").find(".hiddenContent").each(function(){
		$(this).attr("value", $(this).height());
		$(this).hide().css({height: 0}).css("visibility", "visible");
	});

	$("#main .toggleContent").click(function(){
		//store the hidden Content
		var $hiddenContent = $(this).parents(".previewContainer:first").find(".hiddenContent:first");
		//get the Heigt from the value-Attribute
		var height = $hiddenContent.attr("value");
		
		//Condition
		if($hiddenContent.is(':visible')){
			//modify the more-link
			$(this).parents(".previewContainer:first").find("a.moreLink").css("background-position", "left -29px");
			$(this).parents(".previewContainer:first").find("a.moreLink").html("mehr Infos");
			$hiddenContent.animate({ height: 0}, {duration:500, complete: function(){
				$hiddenContent.hide();
			} });
		}else{
			//modify the more-link
			$(this).parents(".previewContainer:first").find("a.moreLink").css("background-position", "left 6px");
			$(this).parents(".previewContainer:first").find("a.moreLink").html("weniger Infos");
			//hide all open Contents
			$("#main .previewContainer").find(".hiddenContent").each(function(){
				if($(this).is(':visible')){
					//modify the more-link for all
					$(this).parents(".previewContainer:first").find("a.moreLink").css("background-position", "left -29px");
					$(this).parents(".previewContainer:first").find("a.moreLink").html("mehr Infos");
					$(this).animate({ height: 0}, {duration:500, complete: function(){
						$(this).hide();
					} });
				}
			});
			//show the active content
			$hiddenContent.show().animate({height: height}, {duration:500});
		}
		return false;
	});
}

function getActiveNavpoint(actLi){	
	if(actLi != null){

		$("#menu li").removeClass("active");
		$(actLi).addClass('active');
		
		$("#newbackgrounddiv").animate({width:$(actLi).width()}, 150);
		$("#backgroundContainer").animate({left:$(actLi).position().left, width:$(actLi).width()}, 150); 		
	}
}

function newSildeNav(){
	$("#homelink").click(function(){
		$("#menu li").removeClass("active");
		$("#menu li:first").addClass("active");
		$("#newbackgrounddiv").animate({width:$("#menu li:first").width()}, { queue:false, duration:150 });
		$("#backgroundContainer").animate({left:0, width:$('#menu li.active').width()}, { queue:false, duration:150 }); 
	});
	
	$('#nav .hlist').append("<div id='backgroundContainer'><div id='newbackgrounddiv'></div><div class='backgroundArrow'></div></div>");
	if($('#menu li.active').width() != null){
		$("#backgroundContainer").css("width", $('#menu li.active').width());
		$("#newbackgrounddiv").css("width", $('#menu li.active').width());
		$("#backgroundContainer").css("left", $('#menu li.active').position().left);
	}else{
		$("#backgroundContainer").css("width", "0px");
		$("#newbackgrounddiv").css("width", "0px");
		$("#backgroundContainer").css("left", "0px");
	}

	
	$("#nav").mouseleave(function(){
		if($('#menu li.active').width() != null){
			$("#newbackgrounddiv").animate({width:$('#menu li.active').width()}, { queue:false, duration:150 });
			$("#backgroundContainer").animate({left:$('#menu li.active').position().left, width:$('#menu li.active').width()}, { queue:false, duration:150 });
		}else{
			$("#newbackgrounddiv").animate({width:"0px"}, { queue:false, duration:150 });
			$("#backgroundContainer").animate({left:"0px", width:"0px"}, { queue:false, duration:150 });
		}
	});
	
	$("#nav li.levelOne").mouseenter(function (){
		var hoverLI = $(this);
		hoverLI.addClass("hover");
		$("#newbackgrounddiv").animate({width:$(this).width()}, { queue:false, duration:150 });
		$("#backgroundContainer").animate({left:$(this).position().left, width:$(this).width()}, { queue:false, duration:150 }); 
		if($(hoverLI).find(".subhlist").is(":visible")==false){
			setTimeout(function(){ 
				if($(hoverLI).hasClass("hover")){
					$(hoverLI).find(".subhlist").slideDown(150);
				}	
			}, 150);
		}
	});
	
	$("#nav li.levelOne").mouseleave(function (){
		$(this).removeClass("hover");
		$(this).find(".subhlist").slideUp(100);
	});
}

