var iCurrent=1; // Start with promo 1
var iMax=4; // Change the iMax number below when adding more promos
var iSeconds=10; // Number of seconds between auto-rotations
var timer; // timer variable

function changePromo(currentID, newID) {
	if (currentID != newID) {
		oCurrent = $('homePromo'+currentID);
		oNew = $('homePromo'+newID);

		Effect.Fade(oCurrent, { duration: .5, from: 1.0, to: 0.0, queue: { position: 'end', scope: 'image', limit: 4 } });
		Effect.Appear(oNew, {queue: { position: 'start', scope: 'image', limit: 4 } });
		iCurrent=newID;
		
		oCurrentNav = $('hpNav'+currentID);
		oNewNav = $('hpNav'+newID);
		
		oCurrentNav.removeClassName('selected');
		oNewNav.addClassName('selected');

		clearInterval(timer);
		timer = setInterval("changePromo(iCurrent, getNextID())", iSeconds*1000);
	}
}

function getNextID() {
	iCurrent==iMax ? iCurrent=1 : iCurrent++;
	return iCurrent;
}

function getPrevID() {
	iCurrent==1 ? iCurrent=iMax : iCurrent--;
	return iCurrent;
}

Event.observe(window, 'load', function() {
	MM_preloadImages(
		'../_images/home-promo-1.jpg',
		'../_images/home-promo-2.jpg',
		'../_images/home-promo-3.jpg',
		'../_images/home-promo-4.jpg'
	);
	
	oCurrentNav = $('hpNav'+iCurrent);
	oCurrentNav.addClassName('selected');
									   
	timer = setInterval("changePromo(iCurrent, getNextID())", iSeconds*1000);
	
	aPromos = $$('div.homePromo');
	aPromos.each(function(s) {
		  // IE needs this to initialize the objects
	});
});