$(document).ready(function() {
	
	var storyHeight = 350;
	var currentTop = 0;
	var waitTime = 6000;
	var animTime = 2000;
	var newsTop = 0;
	var counter = 0;
	
	//get number of stories to display from .Stories #id - this is set in NewsRotator.php
	//Section == 1, stories = 1, Section != 1, stories = 2
	
	//var numDisplayed = 1;
	
	var numDisplayed = $('.Stories').attr('id');
	
	//alert(numDisplayed);
	
	var numStories = $(".Story").size();

	//set css heights
	$('.Stories').css({height:storyHeight*numDisplayed});
	$('.Story').css({height:storyHeight});

	var rotateStories = function(){
			
		if(counter < numStories-2){
			
			newsTop -=storyHeight;
					
			$(".Animator").delay(waitTime).animate({top:newsTop}, animTime, rotateStories);	
			//$(".Stories").delay(timer).animate({}, 1000, );
			counter ++;
		} else {
			newsTop = 0;
			$(".Animator").delay(0).animate({top:newsTop}, 0, rotateStories);
			counter = 0;
		}
		
		//log_debug(counter, numStories-2);
	}
	
	
	//ONLY rotate if more than 3 stories
	if($(".Story").size() > 3){
		rotateStories();	
	}
});


