$(document).ready(function(){
	var imgstartWidth=1688;
	var imgstartHeight=1122;
	function resizeStartImages(){
		var viewportWidth = window.innerWidth ? window.innerWidth : $(window).width();
		var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
		var viewportHeight=viewportHeight-$("#footer").height()+8;
		
		if(viewportWidth/viewportHeight > imgstartWidth/imgstartHeight){
			//Viewport breiter als Bild
			var newWidth=viewportWidth;
			var newHeigth=(newWidth/imgstartWidth)*imgstartHeight;
			$("img.imgstart").width(newWidth).height(newHeigth).css({"left": "0px", "top": "-"+((newHeigth-viewportHeight))+"px"});
		}
		else{
			//Viewport schmaler als Bild
			var newHeigth=viewportHeight;
			var newWidth=(newHeigth/imgstartHeight)*imgstartWidth;
			$("img.imgstart").width(newWidth).height(newHeigth).css({"left": "-"+((newWidth-viewportWidth)/2)+"px", "top": "0px"});			
		}
	}
	$(window).resize(resizeStartImages);
	
	$("div.navigation").hover(
		function(){
			$(this).css("z-index", 1000);
			$("div.subnavigation", this).show().css("z-index", 1000);
			if(isStartPage){
				var imgid="bg_"+$(this).attr("id").substring(3);
				$("body").removeClass().addClass($(this).attr("id").substring(3));
				if($("img.imgstart:visible").attr("id")!=imgid){
					$("img.imgstart:visible").hide();
					$("img#"+imgid).show();
					if(imgid=="bg_therapie"){
						$("#functions a").removeClass("dark");
					}
					else{
						$("#functions a").removeClass("dark").addClass("dark");
					}
				}					
			}
		},
		function(){
			$("div.subnavigation").hide();
	});
	
	$("a.infobox").click(function(e){
		e.preventDefault();
		$("#overlay").show();
		$("#infobox_"+$(this).attr("name")).show();
	});
	$("a.close_infobox").click(function(e){
		e.preventDefault();
		$("#overlay").hide();
		$("div.infobox").hide();		
	});
	resizeStartImages();
});
