﻿var ShowNum = 3; //How many stories to show
var CycleInterval = 5000; //Number of milliseconds to hold story
var StopCycle = 10000; //number of additional milliseconds to hold story if mouseover
var StoryRollcounterx=2; //do not change this unless you want to start with a different story. This is the counter for which story id being shown in the roll
//alert("loaing jacascript");
var StoryRollIntervalID=0;
var AnchorsFixed= false;

function StartTheStories()
{
	if(!AnchorsFixed)
	{
		//alert("Fixing anchors");
		for(var i=1;i<=ShowNum;i++)
			{
	
				var ThisItem = document.getElementById("StoryRollItem_"+i);
				//alert(ThisItem.id);
				var anchors = ThisItem.getElementsByTagName("a");
				//alert(anchors.length);
				for (var j=0;j<anchors.length;j++)
				{			
					anchors[j].onmouseover=function(){StopStoryRoll();};
				}
			}
			
		var RollWrap = document.getElementById("StoryRollBigWrap");
		//alert(RollWrap.id);
		var NumWrap = document.createElement("div");
		NumWrap.id = "StoryRollNumWrap";
		for(var k=1;k<=ShowNum;k++)
		{
			//alert(k);
			var ThisNumRoll = document.createElement("div");
			ThisNumRoll.id = "StoryRollNum_" + k;
			ThisNumRoll.className = "StoryNumRollout";
			
			var ThisNumRollAnchor = document.createElement("a");
			ThisNumRollAnchor.href = "javascript:FocusStory("+k+");";
			var LinkText=document.createTextNode(k);
			ThisNumRollAnchor.appendChild(LinkText);
			
			ThisNumRoll.appendChild(ThisNumRollAnchor);
			
			NumWrap.appendChild(ThisNumRoll);
		}
		
		RollWrap.appendChild(NumWrap);	
		
		AnchorsFixed=true;
	}
	//alert("StartingStories");
	var intervalcode = 'RollTheStories()';
	StoryRollIntervalID= setInterval(intervalcode,CycleInterval);

}

function FocusStory(StoryNum)
{
	StopStoryRoll();
	hideAllStories();
	showThisStory(StoryNum);


}


function showThisStory(storyNum)
{
	document.getElementById("StoryRollItem_"+storyNum).className="StoryRollItemWrap";

	document.getElementById("StoryRollNum_"+storyNum).className="StoryNumRollin";

}

function hideAllStories()
{

	for(var i=1;i<=ShowNum;i++)
	{
		document.getElementById("StoryRollItem_"+i).className="HideMe StoryRollItemWrap";
		document.getElementById("StoryRollNum_"+i).className="StoryNumRollout";

	}
	
}

function RollTheStories()
{
	hideAllStories();
		
	//alert(StoryRollcounterx);
	showThisStory(StoryRollcounterx);
	
	if(StoryRollcounterx==ShowNum)
	{
		StoryRollcounterx=1;
	}
	else
	{
		StoryRollcounterx++;
	}
}

function StopStoryRoll()
{
	//alert("stopstories");
	clearInterval(StoryRollIntervalID);
}