//variables that contain the state of the carousel
var t;
var tt;
var curStory = 1;
var curLeft = 0;
var state = "going";
var lastStory = 5;
var theSection;

//startFeatures is called when the page loads
function startFeatures(){
	lastStory = document.getElementById("boa-content").getElementsByTagName("div").length;
	document.getElementById("bp-"+curStory).className="active";
	t=setTimeout("rotateStories()", 10000);
}//startFeatures()


//functions called by button clicks on the page

function previousItem(){
	transitionStories(0);
}//previousItem

function toggleTimer(){
	var button = document.getElementById("playpause");
	if(state == "going"){
		state = "stopped";
		clearTimeout(t);
		button.src = "/img/ny_lawyer/play.gif";
	}else if(state == "stopped"){
		state = "going";
		rotateStories();
		button.src = "/img/ny_lawyer/pause.gif";
	}
}//toggleTimer

function nextItem(){
	transitionStories(1);
}//nextItem

function displayItem(mySection){
	var curSection = document.getElementById("fc-"+curStory);
	var nextSection = document.getElementById("fc-"+mySection);
	
	document.getElementById("bp-"+curStory).className="";
	document.getElementById("bp-"+mySection).className="active";
	
	curStory = mySection;
	fadeOut(curSection);
	fadeIn(nextSection);
}//displayItem


//functions called by other functions

function rotateStories(){
	transitionStories(1);
	t=setTimeout("rotateStories()", 10000);
}//rotateStories

function transitionStories(direction){
	var curSection = document.getElementById("fc-"+curStory);
	document.getElementById("bp-"+curStory).className="";
	if(direction == 1){
		if(curStory == lastStory){
			curStory = 1;
		}else{
			curStory++;
		}
	}else{
		if(curStory == 1){
			curStory = lastStory;
		}else{
			curStory--;
		}
	}
	
	document.getElementById("bp-"+curStory).className="active";
	
	var nextSection = document.getElementById("fc-"+curStory);
	
	fadeOut(curSection);
	fadeIn(nextSection);
}//transitionStories

function fadeOut(oldSection){
	oldSection.style.display="none";
}//fadeOut

function fadeIn(newSection){
	newSection.style.left="450px";
	curLeft = 450;
	newSection.style.display="block";
	theSection = newSection;
	slide();
}//fadeIn

function slide(){
	if (curLeft==0){
		clearTimeout(tt);
	}else{
		curLeft=curLeft-10;
		theSection.style.left = curLeft + "px";
		tt=setTimeout("slide()", 20);
	}
}//slide


//Tabbed Box -- this is not actually part of the carousel

var currentTab="left";
var currentSection="ReadBox";

function switchTab(tabID, sectionID){
	if(tabID != currentTab){
		document.getElementById(currentTab).className="off";
		document.getElementById(currentSection).style.display="none";
		document.getElementById(tabID).className="on";
		document.getElementById(sectionID).style.display="block";
		currentTab=tabID;
		currentSection=sectionID;
	}
}
