var top = 0;
var subnav_top = 0;
var speed_soll = 0;
var speed_ist = 0;
var subnav_height = 0;
var nav_height = 0;
var reticule = 40;
var x = 0;
	
 $(window).resize(function(){
	// resize height of padding div
   	x = $(window).height() / 2.7;
    $('#outer').css('margin-top', x);
	// resize content fläche unten
	top = 107+x;
	h = $(window).height()-top;
	$('#mitte').css('height',h);
	$('#jquery-overlay').css('height',x*2.7);
	
});
		
$(document).ready(function(){
	var outer = $("#sub_outer");
	var inner = $('#sub_inner'); 
	$(window).resize();
	
	count = 0;
	selectedactive = 0;
	ueberzahl = 0;
	inner.children('li').each(function(){subnav_height += 20; count ++; if ($(this).children("a").hasClass("current")) selectedactive = count;});
	subnav_height += 24;
	nav_height = $('#sub_outer').height()-24;
		
	if (selectedactive-9>0){
		ueberzahl = (selectedactive-8)*20-3;
		
	}

	// reinfahr-animation
	subnav_top = nav_height - subnav_height;
	//alert(subnav_top);
	if (subnav_top <0) subnav_top = 0;
	
	if (navifix == true) {
		inner.css("top", nav_height+50);
		
		inner.animate( {top: subnav_top}, 700, "easeOutSine" , bindevents);
	} else {
		subnav_top -= ueberzahl;
		//alert(subnav_top);
		inner.css("top", subnav_top);
		bindevents();
	};
				  
				  
	function bindevents() {$("#sub_outer").bind("mouseenter", start_scrolling).bind("mouseleave", stop_scrolling);}
	
	outer.mousemove(function(e){
		var clientCoords = parseInt(e.clientY - (x+40 - nav_height));
		if (clientCoords < 0) clientCoords = 0;
		var mouse_dist = clientCoords - (nav_height-40)/2.0;
		if (mouse_dist > 0) {
			mouse_dist -= reticule;
			if (mouse_dist < 0 ) {mouse_dist = 0; speed_soll = speed_ist = 0;}
		}
		if (mouse_dist < 0) {
			mouse_dist += reticule;
			if (mouse_dist > 0 ) {mouse_dist = 0; speed_soll = speed_ist = 0;}
		}
		speed_soll = (mouse_dist)/15.0;
	});
	
	// rollover fade in/out der subnavelemente
	$("#sub_inner a")
		.bind("mouseenter",function(){ $(this).stop();$(this).animate({backgroundColor: rolloverColor, color: "#ffffff"}, 300);})
		.bind("mouseleave",function(){ 
			$(this).stop(); 
			if ($(this).hasClass("current") || $(this).hasClass("section")) $(this).animate({backgroundColor: rolloverColor, color: "#ffffff"}, 1200);
			else $(this).animate({backgroundColor: "#eeeeee", color: "#999999"}, 1200);
		});

	// rollover main nav
	$('#nav a')
		.css( {backgroundPosition: "0 -8px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 37px)"}, {duration:750})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(0 -8px)"}, {duration:750, complete:function(){
				$(this).css({backgroundPosition: "0 -8px"})
			}})
		})
		
	
});

function start_scrolling() {
	$(this).everyTime(20, 'scroller', function() {
		speed_ist += (speed_soll-speed_ist)/10.0;
		subnav_top = subnav_top - speed_ist;
		if (subnav_top>0) subnav_top=0;
		if ((subnav_height+subnav_top) < nav_height) subnav_top= nav_height - subnav_height;
		$(this).children('ul').css("top", subnav_top);
	});
	return false;
}
function stop_scrolling() {
    $(this).stopTime('scroller');
	return false;
}

//Slideshow-Preview einblenden
$(window).load(function(){
	$('#topic .slides .lightbox, #mitte .slides .lightbox').fadeIn("slow");
});
		
		
		
		


