var stories = new Array();
var thumbs = new Array();
var rotating = true;
var position = -2;

function init() {
	stories[0] = document.getElementById('story1');
	stories[1] = document.getElementById('story2');
	stories[2] = document.getElementById('story3');
	stories[3] = document.getElementById('story4');
	thumbs[0] = document.getElementById('thumb1');
	thumbs[1] = document.getElementById('thumb2');
	thumbs[2] = document.getElementById('thumb3');
	thumbs[3] = document.getElementById('thumb4');
	stories[1].style.display = "none";
	stories[2].style.display = "none";
	stories[3].style.display = "none";
	rotate();
}

function rotate() {
	if(rotating){
		position < stories.length-1 ? position++ : position = 0;
		switchStory(position);
		setTimeout(rotate, 7000);
	}
}

function switchRotate() {
	if(rotating == true) {
		rotating = false;
		document.getElementById('storyControl').innerHTML = "Play";
	} else {
		rotating = true;
		document.getElementById('storyControl').innerHTML = "Pause";
	}
	rotate();
}

function apd(){
	rotating = false;
}

function switchStory(story){
	for(i=0; i < stories.length; i++){
		if(i == story){
			stories[i].style.display = "block";
			thumbs[i].style.backgroundColor = "#000";
			position = i;
		} else {
			stories[i].style.display = "none";
			thumbs[i].style.backgroundColor = "transparent";
		}
	}
}
