
// Tabbed content views

function showTab(tabName, rootNodeId)
{
	var node = document.getElementById(rootNodeId);
	if (node)
	{
		node.className = tabName;
	}
}
// END tabbed content views


// Slideshow Theater

var wrapSlideshow = false;
var numSlides = 10;

function disableNext()
{
	disableElement("next");
}

function disablePrev()
{
	disableElement("prev");
}

function disableElement (elemId)
{
	var elem = document.getElementById(elemId);
	elem.className = "disable";
}

function enableLinks()
{
	var nextElem = document.getElementById("next");
	var prevElem = document.getElementById("prev");
	nextElem.className = prevElem.className = "";
}

function changeSlide(doIncrease)
{
  var theaterElem = document.getElementById("theater");
  if (!theaterElem) return false;
  var slideNum = parseInt(theaterElem.className.substr(5),10) - 1;
  if (!wrapSlideshow)
  {
	if ((doIncrease && slideNum == numSlides - 1) ||
		 (!doIncrease && slideNum == 0))
      return;
  }

  if (doIncrease)
    slideNum++;
  else
    slideNum--;
  if (slideNum < 0)
  {
    if (wrapSlideshow)
      slideNum = numSlides - 1;
    else
	{
      slideNum = 0;
	}
  }
  else if (slideNum >= numSlides)
  {
    if (wrapSlideshow)
      slideNum = 0;
    else
	{
      slideNum = numSlides - 1;
	}
  }
  animateTransition(slideNum, doIncrease, "slide" + (slideNum + 1));// + 1 to map it to the 1..N range, from the 0..N-1 range
  if (!wrapSlideshow)
  {
	  enableLinks();
	  if (slideNum == 0)
	  	disablePrev();
	  else if (slideNum == numSlides - 1)
	    disableNext();
  }
}

function nextSlide()
{
  changeSlide(true);
}

function prevSlide()
{
  changeSlide(false);
}

var _animationStep = 0;
var _animationBegin = 0;
var _animationEnd = 0;
var _animationDelay = 50;
var _finalClass = "";
var _interval = null;
function animateTransition(toSlideNumber, isIncreasing, finalClass)
{
	_finalClass = finalClass;
		var elemWidth = document.getElementById("slide1").offsetWidth;
		_animationEnd = - toSlideNumber * elemWidth;
		if (isIncreasing)
		_animationBegin = _animationEnd + elemWidth;
	else
		_animationBegin = _animationEnd - elemWidth;
		_animationStep = 0;
	if (!_interval)
		_interval = window.setInterval(_doAnimateTransition, _animationDelay);
}

var _shiftAmounts = [ 0, 0.03, 0.10, 0.25, 0.5, 0.75, 0.9, 0.97, 1]; // percentages

function _doAnimateTransition()
{
	if ( _animationStep >= _shiftAmounts.length)
	{
		document.getElementById("carousel").style.left = "";
		_animationStep = 0;
		window.clearInterval(_interval);
		_interval = null;
		return;
	}
	document.getElementById("carousel").style.left = (_animationBegin * (1 - _shiftAmounts[_animationStep]) + _animationEnd * _shiftAmounts[_animationStep]) + "px";
	// Set the new class once we've first set the style override. 
	if (_animationStep == 0)
		document.getElementById("theater").className = _finalClass;
	_animationStep++;
}

// END Slideshow Theater

// JavaScript Document
