
//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/tourDeRedmondtile.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.wsdot.wa.gov/traffic/seattle/"), 
	new RotationTarget("Promotions/images/constructionAd.jpg", "newsConstructionUpdates.asp")
);

/* this array represents commute champions */
var commuteChampsTargets = new Array(
	/* image, url */
	new RotationTarget("Promotions/images/cc11dec.jpg", "yourCommuteChamps.asp#december"),
	new RotationTarget("Promotions/images/cc11nov.jpg", "yourCommuteChamps.asp#november"),
	new RotationTarget("Promotions/images/cc11oct.jpg", "yourCommuteChamps.asp#october"),
	new RotationTarget("Promotions/images/cc11sept.jpg", "yourCommuteChamps.asp#september"),
	new RotationTarget("Promotions/images/cc11aug.jpg", "yourCommuteChamps.asp#august"),
	new RotationTarget("Promotions/images/cc11july.jpg", "yourCommuteChamps.asp#july"),
	new RotationTarget("Promotions/images/cc11june.jpg", "yourCommuteChamps.asp#june"),
	new RotationTarget("Promotions/images/cc11may.jpg", "yourCommuteChamps.asp#may"),
	new RotationTarget("Promotions/images/cc11april.jpg", "yourCommuteChamps.asp#april"),
	new RotationTarget("Promotions/images/cc11march.jpg", "yourCommuteChamps.asp#march"),
	new RotationTarget("Promotions/images/cc11feb.jpg", "yourCommuteChamps.asp#february"),
	new RotationTarget("Promotions/images/cc11jan.jpg", "yourCommuteChamps.asp#january"),
	new RotationTarget("Promotions/images/ccnominate.jpg", "yourCommuteChampsInfo.asp")
);

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);
}


