
//an array to hold what position each of the three rotating objects are in
var rotationTicCounts = new Array(0, 0, 0);

function RotationTarget(image, url)
{
  this.Image = image;
  this.Url = url;
}

/* this array represents current promotions */
var promotionTargets = new Array(
	/* image, url */	
	new RotationTarget("images/calendarPromo.gif", "calendarOfPromosAndEvents.asp"),
	new RotationTarget("images/WOlogoMarchOct.jpg", "WOPromo.asp"),
	new RotationTarget("images/earthDayAndMonth.jpg", "earthDayAndMonthPromo.asp"),
	new RotationTarget("images/bikeToWorkDayMonthPromo.jpg", "bikeToWorkPromo.asp"),
	new RotationTarget("images/tourDeRedmond2010.jpg", "tourDeRedmondPromo.asp"),	
	new RotationTarget("images/ecoFairDerbyDaysPromo.gif", "ecoFairPromo.asp"),
	new RotationTarget("images/promoPoster3.png", "yourCommuteCash.asp"),
	new RotationTarget("images/rideshareOnlinePromo.gif", "RideshareOnlinePromo.asp"),
	new RotationTarget("images/commuteChampPromo.jpg", "yourCommuteChampsInfo.asp"),
	new RotationTarget("images/banner-for-newsletter.jpg", "yourNewsletterMain.asp")
		
);

/* this array represents member spotlight */
var spotlightTargets = 	new Array(
	/* image, url */
	new RotationTarget("Promotions/images/liveRegionalPromo.jpg","http://www.rpin.org/rpinweb/TrafficRoadConditions.aspx"), 
	new RotationTarget("Promotions/images/constructionAd.jpg", "newsConstructionUpdates.asp")
);

/* this array represents commute champions */
var commuteChampsTargets = new Array(
	new RotationTarget("Promotions/images/elaine.jpg", "yourCommuteChamps.asp#elaineA"),
	new RotationTarget("Promotions/images/brad.jpg", "yourCommuteChamps.asp#bradB"),
	new RotationTarget("Promotions/images/mike.jpg", "yourCommuteChamps.asp#mikeB"),
	new RotationTarget("Promotions/images/debra.jpg", "yourCommuteChamps.asp#debraB"),
	new RotationTarget("Promotions/images/daniela.jpg", "yourCommuteChamps.asp#danielaC"),
	new RotationTarget("Promotions/images/ninyana.jpg", "yourCommuteChamps.asp#ninyanaD"),
	new RotationTarget("Promotions/images/jd.jpg", "yourCommuteChamps.asp#jdF"),
	new RotationTarget("Promotions/images/eli.jpg", "yourCommuteChamps.asp#eliG"),
	new RotationTarget("Promotions/images/per.jpg", "yourCommuteChamps.asp#perN"),
	new RotationTarget("Promotions/images/ben.jpg", "yourCommuteChamps.asp#benS"),
	new RotationTarget("Promotions/images/markS.jpg", "yourCommuteChamps.asp#markS"),
	new RotationTarget("Promotions/images/markT.jpg", "yourCommuteChamps.asp#markT")
);

var targetArrays = new Array(
	promotionTargets, 
	spotlightTargets,
	commuteChampsTargets
);

//this takes in the number of an array and it's current position
//it returns the position of the array you are asking about
function getRotationValue(targetNumber, ticCount)
{   
    /*get the array you want to manipulate*/
    var targetArray = targetArrays[targetNumber];
	/* makes the tic count wrap when it gets to length */
    var index = ticCount % targetArray.length;
    if(index < 0) index += targetArray.length;
    return targetArray[index];
}

/* based on the target number (which array) figure out which*/
function getRotationTargetElement(targetNumber)
{
    return document.getElementById("rotationTarget" + targetNumber);
}

function modifyTarget(targetElement, value)
{
    targetElement.src = value.Image;
	var parentAnchor = targetElement.parentNode;
	parentAnchor.href = value.Url;
}

function rotateValue(targetNumber, direction)
{
	if(targetNumber != null)
	{
		restartRotation();
	}
    for(var i = 0; i < 3; i++)
    {
        if((i == targetNumber) || (targetNumber == null))
        {
            rotationTicCounts[i] += direction;
            var targetElement = getRotationTargetElement(i);
            var newValue = getRotationValue(i, rotationTicCounts[i]);
            modifyTarget(targetElement, newValue);
        }
    }        
}

var rotationTimerId;

function stopRotation()
{
	window.clearInterval(rotationTimerId);
}

function restartRotation()
{
	stopRotation();
	startRotation();
}

function startRotation()
{
	rotateValue(null, 0);
    rotationTimerId = window.setInterval('rotateValue(null, 1)', 5000);
}

