$(document).ready(function() {
	//Hintergrundbild Fading
	$("#page-wrap").after('<div class="fading"></div>');
	for (var i = 0; i < 9; i++){
		$(".fading").append('<div id="fading-bg-' + i + '" class="fading-bg"></div>');
	}
	$('.fading').cycle({
		fx: 'fade',
		random: 1,
		speed:    2000, 
		timeout:  8000
	});
	$('#page-wrap').resize(fixFadingContainerHeight);
	fixFadingContainerHeight();
	
	// Einblendung des Enter-Buttons bei Video-Intro erst nach 5 Sekunden
	//$('#intro .box').hide().delay(5000).fadeIn("slow");
	
	//Intro-Button
	$('.btn_enter a').mouseover(function(){
		$('.btn_enter').addClass('btn_enter_hover');
	 });
	 $('.btn_enter a').mouseout(function(){
		$('.btn_enter').removeClass('btn_enter_hover');
	 });
	
	//Facebook Bar
    $('.btn_facebook').removeClass('btn_facebook_expand');
    $('.btn_facebook').click(function(){
        $('.facebook_margins').slideToggle(function(){
            $('.btn_facebook').toggleClass('btn_facebook_expand');
        });
        return false;
    });
	
	//HIDE SECOND LEVEL IN THE MAINNAVIGATION
	$(".level2").hide();
	$(".level2").delay(300).slideDown('slow');
	$(".level2-active").show();
	
});

$(window).load(function() {
	fixContentHeight();
	$(window).resize(fixContentHeight);
});

function fixFadingContainerHeight(){
	$('.fading > div').height($('#page-wrap').height());
}

function fixContentHeight(){
	$('#main-nav').height('');
	$('#main').height('');
	viewPortHeight = $(window).height();
	pageHeight = $('#page').height() + 50;
	if (viewPortHeight > pageHeight){
		diffHeight = viewPortHeight - pageHeight;
		$('#main-nav .nav').height(pageHeight + diffHeight -170);
		$('#main').height(pageHeight + diffHeight -50);
	}
	else {
		$('#main-nav .nav').height(pageHeight -170);
	}
}
