$(document).ready(function(){
	//Anfangszustand
	function reset() {
		for(i=1; i<=9; i++) {
			var selector = '#news' + i;
			$(selector).hide();
		}
		for(i=1; i<=3; i++) {
			var selector = '#newsBlock' + i;
			$(selector).hide();
		}
	}
	reset();
	news1();
	var newsBlock = 1;
	var animationStat = 1;
	
	//News1 einblenden
	function news1() {
		newsBlock = 1;
		$('#newsBlock1').show();
		$('#newsNav1').css('background-color', '#FFFF00');
		$('#news1').show('500', function() {
			$('#news2').show('500', function() {
				$('#news3').show('500', function() {
					newsTimeout = window.setTimeout(function() {
						//alert ('animationStat: ' + animationStat);
			        	if(animationStat != 0) {
			        		$('#newsBlock1').slideUp('slow', function() {
				        		$('#newsNav1').css('background-color', '#007CC3');
				        		reset();
				        		news2();
			        		});
			        	}
			        	//else return;
					}, 7000); 	
			    });
		    });
	    });
	}
	//News2 einblenden
	function news2() {
		newsBlock = 2;
		$('#newsBlock2').show();
		$('#newsNav2').css('background-color', '#FFFF00');
		$('#news4').show('500', function() {
			$('#news5').show('500', function() {
				$('#news6').show('500', function() {
					newsTimeout = window.setTimeout(function() {
						//alert ('animationStat: ' + animationStat);
			        	if(animationStat != 0) {
			        		$('#newsBlock2').slideUp('slow', function() {
				        		$('#newsNav2').css('background-color', '#007CC3');
				        		reset();
				        		news3();
			        		});
			        	}
			        	//else return;
					}, 7000);
			    });
		    });
	    });
	}
	//News3 einblenden
	function news3() {
		newsBlock = 3;
		$('#newsBlock3').show();
		$('#newsNav3').css('background-color', '#FFFF00');
		$('#news7').show('500', function() {
			$('#news8').show('500', function() {
				$('#news9').show('500', function() {
					newsTimeout = window.setTimeout(function() {
						//alert ('animationStat: ' + animationStat);
			        	if(animationStat != 0) {
			        		$('#newsBlock3').slideUp('slow', function() {
				        		$('#newsNav3').css('background-color', '#007CC3');
				        		reset();
				        		news1();
			        		});
			        	}
			        	//else return;
					}, 7000);
			    });
		    });
	    });
	}
	//Animation stoppen
	$('#newsBut').click(function() {
		if (animationStat == 1) {
			animationStat = 0;
			$(this).css('background-position', '0 0');
		}
		else if (animationStat == 0) {
			animationStat = 1;
			$(this).css('background-position', '0 -15px');
			window.clearTimeout(newsTimeout);
			var selector1 = '#newsBlock' + newsBlock;
			var selector2 = '#newsNav' + newsBlock;
			$(selector1).slideUp('slow', function() {
				$(selector2).css('background-color', '#007CC3');
        		reset();
        		//alert ('animationStat: ' + animationStat + '\n' + 'newsBlock: ' + newsBlock);
        		switch (newsBlock) {
					case 1:
						news2();
						break;
					case 2:
						news3();
						break;
					case 3:
						news1();
						break;
        		}
			});
		}
	});
});

