
//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("Promotions/images/promoWOFall2009.jpg", "your2009OctWOPromo.asp"),
	new RotationTarget("images/tdr2009promo.jpg", "http://www.tour.grtma.org/"),	
	new RotationTarget("Promotions/images/ecSummer09.jpg", "yourNewsletterMain.asp"),
	new RotationTarget("images/vanpoolPromoHome.gif", "yourPromotionsCurrent.asp#vanpromo"),
	new RotationTarget("images/promoPoster3.png", "yourCommuteCash.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/barbAngellCC09promo.jpg", "yourCommuteChamps.asp#barbA"),
	new RotationTarget("Promotions/images/jimBevanCC09promo.jpg", "yourCommuteChamps.asp#jimB"),
	new RotationTarget("Promotions/images/clayDawsonCC09promo.jpg", "yourCommuteChamps.asp#clayD"),
	new RotationTarget("Promotions/images/steveFaiksCC09promo.jpg", "yourCommuteChamps.asp#steveF"),
	new RotationTarget("Promotions/images/kiranGadepalliCC09promo.jpg", "yourCommuteChamps.asp#kiranG"),
	new RotationTarget("Promotions/images/paulHopeCC09promo.jpg", "yourCommuteChamps.asp#paulH"),
	new RotationTarget("Promotions/images/candaceHortonCC09promo.jpg", "yourCommuteChamps.asp#candaceH"),
	new RotationTarget("Promotions/images/erinKellyCC09promo.jpg", "yourCommuteChamps.asp#erinK"),
	new RotationTarget("Promotions/images/davePooleCC09promo.jpg", "yourCommuteChamps.asp#daveP"),
	new RotationTarget("Promotions/images/garySolidayCC09promo.jpg", "yourCommuteChamps.asp#garyS"),
	new RotationTarget("Promotions/images/fergusStewartCC09promo.jpg", "yourCommuteChamps.asp#fergusS"),
	new RotationTarget("Promotions/images/tomTrombleyCC09promo.jpg", "yourCommuteChamps.asp#tomT")
);

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);
}

