$(function(){
	$('.navigation_showLevel1 li.nav_4').css('display','none');
	if ($('.navigation_showCompleteCombinedNavigation li.act').length) {
		
		$('.navigation_showCompleteCombinedNavigation').children().css('display','none');
		$('.navigation_showCompleteCombinedNavigation li.nav_0').css('display','block');
		$('.navigation_showCompleteCombinedNavigation li.nav_4').css('display','block');
		$('.navigation_showCompleteCombinedNavigation li.act').css('display','block');
	}
	var children_secondnav_titles = $('.navigation_showCompleteCombinedNavigation li.act .secnavi li.headline_nav');
	
	if (children_secondnav_titles.length > 2) {
		var general_nav = $('<ul class="general_nav"></ul>').appendTo('.navigation_showCompleteCombinedNavigation li.act');

		for (i = 2; i < children_secondnav_titles.length; i++)
		{
			children_secondnav_title = $(children_secondnav_titles[i]);
			children_secondnav_li = children_secondnav_title.nextUntil('li.headline_nav');
			children_secondnav_li = $.merge(children_secondnav_title, children_secondnav_li);
			new_list = $('<li><ul></ul></li>').appendTo(general_nav);
			children_secondnav_li.appendTo(new_list.children());
		}
	}
	
	if ($('#search2_showForm-text')) {
		
		var query = {
			de: "Suche",
			en: "search"
		}
		
		$('#search2_showForm-text').val(query[window.novalux_lang]);
		
		$('#search2_showForm-text').focus(function() {
			if (this.value == query[window.novalux_lang]) {
				this.value = "";	
			}
		});
		
		$('#search2_showForm-text').blur(function() {
			if (this.value == "") {
				this.value = query[window.novalux_lang];	
			}
		});
		
	}
	
	
	$("div.overlay_wrapper").hide();
	
		var overlayHeight = $('div.overlay_wrapper').outerHeight();
			$("ul.navigation_showCompleteCombinedNavigation > li").each(function(){
				if (!$(this).hasClass('nav_0') && !$(this).hasClass('nav_4')){
					$(this).hover(
						function() {
							$("div.overlay_wrapper").fadeIn();
						},
						function() {
							$("div.overlay_wrapper").fadeOut();
						}
					);
				}
			});
	
																																	
	if ($('#faq_showSlide'))
		setFaqSlide();
		
	if ($('.general_nav')) {
		$('.general_nav').remove().appendTo('.navigation_showCompleteCombinedNavigation li.act');
	}
	
	if ($('#keyvis') != null)
		calcContentHeight();
});

function getWindowHeight() {

	var windowHeight = 0;
 	
	if (typeof(window.innerHeight) == 'number')	{
 		windowHeight = window.innerHeight;
 	} else {
 		if (document.documentElement && document.documentElement.clientHeight) {
		 	windowHeight = document.documentElement.clientHeight;
	 	}	else {
	 		if (document.body && document.body.clientHeight) {
			 	windowHeight = document.body.clientHeight;
		 	}
	 	}
 	}
 	
	return parseInt(windowHeight);
}
 	


function calcContentHeight() {
	var windowHeight = getWindowHeight();
	var contentHeight = $('#content').outerHeight() + $('#header').outerHeight() + $('#main-nav').outerHeight();
	var mainHeight = $('#main').outerHeight() + $('#header').outerHeight() + $('#main-nav').outerHeight();
	var contentWrapperHeight = getWindowHeight() - $('#header').outerHeight() - $('#main-nav').outerHeight();
	
	if ($('#main').length && windowHeight < mainHeight) {
		$('#keyvis').css('height',mainHeight + 'px');
	} else {
		$('#keyvis').css('height',windowHeight + 'px');
	}

	if ($('#main').length && windowHeight < mainHeight) {
		$('#footer').css('top', mainHeight + 'px');
		$('div.overlay_wrapper').css('height', mainHeight + 'px');
		if ($('#content').length) {
			$('#content').css('height', $('#page').height() - $('#content').offset().top - 50 + 'px');
		}
		
	} else {
		$('#footer').css('top', (windowHeight) -20 + 'px');
		$('div.overlay_wrapper').css('height', windowHeight + 'px');
		if ($('#content').length) {
			$('#content').css('height', $('#page').height() - $('#content').offset().top - 70 + 'px');
		}
	}
	
	$('div.overlay_wrapper').css('width', document.documentElement.clientWidth);
	
	
	
	if ($('body.edit').length) {	
		$('#keyvis img.teaser_showRotation').css('height', mainHeight + 'px');
	}

}

$(window).load(function(){
	calcContentHeight();	
});

$(window).resize(function(){
	calcContentHeight();
});

// slide for the FAQ module
function setFaqSlide() {
	$("#faq_showSlide li div.content").hide();
	
	$("#faq_showSlide li h5").click( function() {
			if ($($(this).parent().find("div.content")).hasClass('open')) {
				$($(this).parent().find("div.content")).animate({
					height: 'hide',
					opacity: 'hide'
				}, 'slow');
				
				$("#faq_showSlide li div.content").removeClass('open');

				$('#faq_showSlide li h5').removeClass('open');
				
			} else {
					$('#faq_showSlide li h5').removeClass('open');
					$(this).addClass('open');
					
					$("#faq_showSlide li div.open").animate({
						height: 'hide',
						opacity: 'hide'
					}, 'slow');
					
					$($(this).parent().find("div.content")).animate({
						height: 'show',
						opacity: 'show'
					}, 'slow');
	
					$("#faq_showSlide li div.content").removeClass('open');	
					
					$($(this).parent().find("div.content")).addClass('open');
					
			}
																						
																						
	});
	
	
}
