// Varaiblen
slideSpeed = 250;
fadeSpeed = 250;
initalmainboxheight = 1000;
standardsearchtext = '';

pagewidthleft = 1313;
pagewidthcenter = 1626;

$(document).ready(function(){
	
	//********************************************
	// Subnavigation bei Mouseover einblenden
	$('ul#navigation-list li.navi-element').each(function(){
		if($(this).find('.subnavigation-list').length > 0) {
			$(this).mouseenter(function(){
				$(this).find('.subnavigation-list').stop(true,true).fadeIn(slideSpeed);
			});
			$(this).mouseleave(function(){
				$(this).find('.subnavigation-list').stop(true,true).fadeOut(slideSpeed);
			});
		}
	});
	//********************************************
	
	//********************************************
	//Listenelemente in Naviagtion selbst klickbar machen (nicht nur die Links)
	$("#navigation-list a[href]").each(function(){
		var link = $(this).attr("href");
		$(this).parent().css("cursor","pointer");
		$(this).parent().click(function(){
			window.open(link, "_self");
		});
	});
	//********************************************
	
	//********************************************
	//Main-Box-Länge über ganzen Bildschirm - initial
	initalmainboxheight = $('#main-box').height();
	
	if($(window).height() > $('#main-box').height()) {
		$('#main-box').css('height',(Math.round($(window).height())+'px'));
	} else {
		$('#main-box').css('height',($('#main-box').attr('rel')+'px'));
	}
	//********************************************


	//********************************************
	//Hintergrundbild-Anpassung je nach Breite des Anzeigebereichs -initial
	currentwindowheight = $(window).height()
	currentwindowidth = $(window).width()
	
	if(currentwindowidth < 1281){
		$("#bdy").addClass("small");
	}
	
	/*currentmainboxheight = $('#main-box').height();
	if(currentwindowidth < pagewidthleft) {
		$('#main-box').css('margin','0px');
		$('body').css('background-position',(-$('#main-box').width()/2)+'px 0');
		//$('body').css('background-position','top right');
	} else if(currentwindowidth < pagewidthcenter) {
		$('#main-box').css('margin','0px 0px 0px '+(currentwindowidth-pagewidthleft)+'px');
		$('body').css('background-position',(-$('#main-box').width()/2+currentwindowidth-pagewidthleft)+'px 0');
	} else {
		$('#main-box').css('margin','0px auto');
		$('body').css('background-position','top center');
	}*/
	
	//********************************************



	//********************************************
	// Suchen-Eingabe feld Standardtext
	standardsearchtext = $("#search-text").val();
	$("#search-text").focus(function(){
		if($(this).val() == standardsearchtext) {
			$(this).val("");
		}
	});

	$("#search-text").focusout(function(){
		if($(this).val() == "") {
			$(this).val(standardsearchtext);
		}
	});
	//********************************************

	$('.subnavi-element a').each(function(){
		var text = $(this).html();
		var textersetzt = text.replace(/ /g, "&nbsp;");
		$(this).html(textersetzt);
	});


	//********************************************
	// Kursplan
    if($('.kursplan').length > 0){
        $('.kurs').mouseenter(function() {
            if(!$(this).hasClass('leer')){
                $('.kurs').stop();
                $(this).css('opacity','1').addClass('nofadeout');   
                $('.kurs').each(function(){
                    if(!$(this).hasClass('nofadeout')){
                        $(this).animate({
                            opacity: 0.5
                        },200);
					}
                });
            }
        });
        
        $('.kurs').mouseleave(function() {
            $('.kurs').stop();
            $(this).removeClass('nofadeout');   
            $('.kurs').animate({
                opacity: 1
            },200);
        }); 
        
        $('.kurs').each(function(){
            if($(this).attr('rel') != ''){
                $(this).tinyTips('light', $(this).attr('rel'));
            }
        });
    }	
	//********************************************
	
	$('a[rel=fnc]').fancybox();
	
	$('a.fncp').fancybox({
		'overlayShow'	: true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'width'			: 895,
		'height'		: 465,
		'type'			: 'iframe',
		'scrolling'		: 'no'		
	});
});

$(window).resize(function(){
	// Variablen
	currentwindowheight = $(window).height()
	currentwindowidth = $(window).width()
	currentmainboxheight = $('#main-box').height();


	//********************************************
	//Main-Box-Länge über ganzen Bildschirm - bei Resize
	if(currentwindowheight > currentmainboxheight) {
		$('#main-box').css('height',(parseInt(currentwindowheight)+'px'));
	}
	if (currentwindowheight < initalmainboxheight) {
		$('#main-box').css('height',(parseInt(initalmainboxheight)+'px'));
	}
	//********************************************

	if(currentwindowidth < 1281){
		$("#bdy").addClass("small");
	}
	
	//********************************************
	//Hintergrundbild-Anpassung je nach Breite des Anzeigebereichs
	/*if(currentwindowidth < pagewidthleft) {
		$('#main-box').css('margin','0px');
		$('body').css('background-position',(-$('#main-box').width()/2)+'px 0');
		//$('body').css('background-position','top right');
	} else if(currentwindowidth < pagewidthcenter) {
		$('#main-box').css('margin','0px 0px 0px '+(currentwindowidth-pagewidthleft)+'px');
		$('body').css('background-position',(-$('#main-box').width()/2+currentwindowidth-pagewidthleft)+'px 0');
	} else {
		$('#main-box').css('margin','0px auto');
		$('body').css('background-position','top center');
	}
	*/
	//********************************************
});
