$(window).load(function(){
	var h2height = 0;
	var navHeight = $( ".articleRotationNavContainer" ).innerHeight();
	var autointerval = 6000;
	
	$( ".articleRotationNavContainer h2" ).each(
	function(){
	h2height = h2height + $(this).innerHeight();
	});
	
	var articleheight = navHeight - h2height;
	
	$(".rotationArticle").css("height", articleheight + "px");
	
	var images = $(".articleRotator").scrollable({ 
		size: 1, 
		clickable: false,
		circular: true,
		api: true
	}); 
	
	var accordion = $(".articleRotationNavContainer").tabs(".articleRotationNavContainer div.rotationArticle", {
		tabs: 'h2',
		effect: 'slide',
		initialIndex: -1,
		rotate: true,
		api: true 
	});
	var stepcount = 0;
	function stepForward(){
		
		var accordIndex = accordion.getIndex();
		if(accordIndex < 0 || accordIndex == null){
			accordion.click(1);
			images.seekTo(1);
			
		}else{
			images.next();
			accordion.next();
		}
		
		
	};
	function stepTo(target){
		images.seekTo(target);
	};
	accordion.onClick(function(event, tabIndex){
		stepTo(tabIndex);				   
	});
	
	var autostep = window.setInterval(stepForward, autointerval);
	
	$(".articleRotatorContainer").hover(
		function(){
			window.clearInterval(autostep);
		},function(){
			autostep = window.setInterval(stepForward, autointerval);
		});
	});