var myStory;
var Story;
var automaticRotate = true;

//Display the currently selected student
function currentStory(myStory, stopAutomatic){
	if ((myStory == null) || (parseInt(myStory) > 4 )|| (parseInt(myStory) < 1 )) {
		myStory = 1;
	}
	Story = myStory;
	
	if (stopAutomatic == true) {
		automaticRotate = false;
	}
	
	showStory(myStory);
	return false;
}

function showStory(myStory) {
	// Diable all stories and then enable current story
	$('#stories .story').removeClass('active');
	$('#story' + myStory).addClass('active');	
	$('#stories .story').hide();
	$('#story' + myStory).fadeIn('slow');

	// Activate the right menu item
	$('#menu .menu-item').removeClass('active');
	$('#menu' + myStory).addClass('active');
	return null;
}

$(document).ready(function() {
	currentStory(1);
    var interval = setInterval(function(timer) {
		if (automaticRotate == false) {
            clearInterval(interval);
		} else {
			Story = Story + 1;
			if (Story > 4) { 
				Story = 1
			}
			currentStory(Story, false);
		}
	}, 8000);
});
