$(function() {

	var interval = 7000;
	var duration = 2000;
	var nummer = 0;
	
// Runs the newsSlider function every n sec - checked - OK
theMovie = setInterval (function(){
		newsSlider();
	}, interval);

// the newsSlider animation code
	function newsSlider(){
		var currentPhoto = $("#newsroller_content .slide.current");
		var nextPhoto = currentPhoto.next();
		if (nextPhoto.length == 0)
			nextPhoto = $("#newsroller .slide:first");
			
		var currentTab = $("#newsroller_tab li.current");
		var nextTab = currentTab.next();
		if (nextTab.length == 0)
			nextTab = $("#newsroller_tab li:first");
		
		currentPhoto.removeClass("current").addClass("previous");
		nextPhoto.css({ opacity: "0" }).addClass("current").animate({opacity: "1"}, duration, 
			function(){
			currentPhoto.removeClass("previous");
			});
		currentTab.css({backgroundPosition: "0 0"});	
		nextTab.animate({
			backgroundPosition: "(0 -100px)"
			}, duration,
			function(){
			currentTab.removeClass("current");
			nextTab.addClass("current");
			});

	
	};
		
// stops the animation when hovering over
	$("#newsroller_tab").mouseover(function(){
		clearInterval( theMovie );
		$("#newsroller_tab li.current").css({backgroundPosition: "0 0"});
		$("#newsroller_tab li.current").removeClass("current");
		$("#newsroller_content .slide .current").removeClass("current");
	});

// changes when list item is hovered
	$("#newsroller_tab li").hover(
			function(){
				$("#newsroller_content .slide.ontop").removeClass("ontop");
				nummer = $(this).index();
				$("#newsroller_tab li").css({backgroundPosition: "0 0"});
				$(this).css({backgroundPosition: "0 -100px"});
				$("#newsroller_content .slide:eq(" + (nummer) + ")").addClass("ontop");
			},
			function(){
				$("#newsroller_tab li").css({backgroundPosition: "0 0"});
				$(this).css({backgroundPosition: "0 -100px"});
			});
		

});


