var iCurrentPromo, iMaxPromo, iPromoSeconds, promoTimer;

function changePromo(currentID, newID) {
	if (currentID != newID) {
		oCurrent = $('hp'+currentID);
		oNew = $('hp'+newID);

		// Cross Fade one panel into the other
		new Effect.Parallel(
			[
				Effect.Fade(oCurrent, { sync: true }),
				Effect.Appear(oNew, { sync: true })
			],
			{ duration: .5 }
		);
		
		iCurrentPromo=newID;
		clearInterval(promoTimer);
		promoTimer = setInterval('changePromo(iCurrentPromo, getNextPromoID())', iPromoSeconds*1000);
		
		oCurrentNav = $('hpnav'+currentID);
		oCurrentNav.removeClassName("selected");
		oNewNav = $('hpnav'+newID);
		oNewNav.addClassName("selected");
	}
}
		
function getNextPromoID() {
	iCurrentPromo==iMaxPromo ? iCurrentPromo=1 : iCurrentPromo++;
	return iCurrentPromo;
}

function getPrevPromoID() {
	iCurrentPromo==1 ? iCurrentPromo=iMaxPromo : iCurrentPromo--;
	return iCurrentPromo;
}
		
Event.observe(window, 'load', function() {
	// Initialize values on page load
	iCurrentPromo = 1; //Start with first promo
	
	iMaxPromo = $('homePromos').getElementsByTagName('img').length; // Set the number of promos by the number of images inside the promos container

	iPromoSeconds = 10; //Number of seconds between rotations
	
	oCurrentNav = $('hpnav1');
	oCurrentNav.addClassName("selected");
	
	promoTimer = setInterval('changePromo(iCurrentPromo, getNextPromoID())', iPromoSeconds*1000); //Timer to rotate promos
});
