nt_curr = 1;
anim = true;
max = 5;
to_ref = 0;
aplay = true;
clickid = 1;

function nt_fade(num) {

	if(num != nt_curr && anim) {
		var dur = 500;
		anim = false;

		for( i=1; i<=max; i++ ) {
			if( num != i ) {
				$("#ntn_"+i).css("z-index", 0);		
				$('#ntbtn_'+i+' * p').css("font-weight", "normal");
				$("#ntbtn_"+i).animate({top: -5}, 100);
			}
		}

		$('#ntbtn_'+num+' * p').css("font-weight", "bold");
		$("#ntbtn_"+num).animate({top: 0}, 100, function() { clickid = num; } );

		$("#ntn_"+nt_curr).css("z-index", 0).animate({opacity: 0}, dur, function() {
			$("#ntn_"+nt_curr).css("display", "none");
			nt_curr = num;
		});
		$("#ntn_"+num).css("z-index", 1).css("display", "block").animate({opacity: 1}, dur, function() {
			for( var i=1; i<=max; i++ ) {
				if( num != i )
					$("#ntn_"+i).css("display", "none");			
			}
			anim = true;
		});
	}
}

function autoplay(on, dur, num) {
	window.clearTimeout(to_ref);
	if( on ) {
		dur = (dur) ? dur : 5000;
		var nxtnum = num ? num+1 : nt_curr + 1;	
		if( nxtnum > max ) nxtnum = 1;	
		to_ref = window.setTimeout("nt_fade("+nxtnum+");autoplay("+aplay+")", dur);
	}
}

$(window).load(function () {
	autoplay(aplay);
		
	$(".ntnavbtn").mouseover( function() {
		id = $(this).attr("id");
		idn = parseInt(id[6])-1;
		$(this).animate({top: 0}, 100);
	});
	
	$(".ntnavbtn").mouseleave( function() {
		id = $(this).attr("id");
		idn = parseInt(id[6]);
		if( nt_curr != idn && clickid != idn ) $(this).animate({top: -5}, 200);
	});
	
	$(".ntnavbtn").click( function() {
		clickid = parseInt($(this).attr("id")[6])
		nt_fade(clickid);
		autoplay(aplay, 10000, clickid);
	});
	
	$("#ntn_2, #ntn_3, #ntn_4, #ntn_5").css("opacity", 0);

	/*$("a#noap").click( function(event) {
		event.preventDefault();
		if( aplay ) {
			aplay = false;
			autoplay(false);
			$(this).text("Autoplay aktivieren");
		} else {
			aplay = true;
			autoplay(true);
			$(this).text("Autoplay deaktivieren");
		}
	});*/
});
