//scrollit function & declarations
//john reeve did this

var x = 0;
var destination = 0;
var maxWidth = 0;
var incScroll = 50;
var speedScroll = 50;
var columnWidth = 150;
var slideTimer = 0;

isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;

function primeX(xValue) {
	//calculate x by number of columns
	if (isIE5 || isNS6)
		widthTimeline =  document.getElementById('navTimeline').style.width;
	else if (isIE4)
		widthTimeline = document.all['navTimeline'].style.width;
	else
		widthTimeline = document.layers['navTimeline'].width;
	widthTimeline = widthTimeline.replace("px","");
	x = xValue;
	x *= -1;
	//turn off the future button if needed
	if(xValue == widthTimeline - 750) forwardButton("off");
}


function scrollit(direction) {
	beginPoint = 0;
	clearInterval(slideTimer);

	if (isIE5 || isNS6)
		endPoint = document.getElementById('navTimeline').style.width;
	else if (isIE4)
		endPoint = document.all['navTimeline'].style.width;
	else
		endPoint = document.layers['navTimeline'].width;
		
	endPoint = endPoint.replace("px","");
	endPoint = (endPoint - columnWidth * 5) * -1;

	//hardcode the columnwidth
	if (direction == "b") { destination = x + columnWidth; }
	else if (direction == "f") { destination = x - columnWidth; }
	else { 
		destination = direction; 
		if (x > destination) { direction = "f"; }
		else { direction = "b"; }
	}
	//alert("destination" + destination + " endPoint" + endPoint + " beginPoint" + beginPoint);
	//check to see if the slide should stop
	if (destination <= beginPoint && destination >= endPoint) {
		slideTimer = setInterval("slideTo(" + destination+ ",'" + direction + "')", speedScroll);

		//these lines of code control the appearance of the back button
		if (destination + columnWidth > beginPoint)  //beginning
			backButton("off");
		else
			backButton("on");
		
		//these lines of code control the appearance of the forward button
		if (destination - columnWidth < endPoint) //end
			forwardButton("off");
		else 
			forwardButton("on");
	}
}

function backButton(status) {
	if (status == "on") {
		document['nav_past'].src = "artwork/nav_past_off.gif";
		nav_past_on.src = "artwork/nav_past_on.gif";
		nav_past_off.src = "artwork/nav_past_off.gif";
	}
	else {
		document['nav_past'].src = nav_past_disabled.src;
		nav_past_on.src = nav_past_disabled.src;
		nav_past_off.src = nav_past_disabled.src;
	}
}

function forwardButton(status) {
	if (status == "on") {
		document['nav_future'].src = "artwork/nav_future_off.gif";
		nav_future_on.src = "artwork/nav_future_on.gif";
		nav_future_off.src = "artwork/nav_future_off.gif";
	}
	else {
		document['nav_future'].src = nav_future_disabled.src;
		nav_future_on.src = nav_future_disabled.src;
		nav_future_off.src = nav_future_disabled.src;
	}
}

function slideTo(destination,direction) {
	var increment = 0;
	//if moving forward
	if (direction == "f") { 
		if (x <= destination) { 		
			clearInterval(slideTimer);
		}
		else {
			increment = incScroll * -1; 
			moveLayer(increment);
		}
	}
	//if moving backward
	else if (direction == "b") { 
		if (x >= destination) { 		
			clearInterval(slideTimer);
		}
		else {
			increment = incScroll; 
			moveLayer(increment);
		}
	}
	x += increment; //don't forget to update this global x coordinate :)
}

function moveLayer(increment) {
	if (isIE5 || isNS6) {
		document.getElementById('navTimeline').style.left = x + increment;
	}
	else if (isIE4) {
		document.all['navTimeline'].style.left += increment;
	}
	else {
		document.layers['navTimeline'].left += increment;
	}
}