var rotator = new Object();
rotator.interval = 9000;
rotator.count = 1;
rotator.currentItem = 1;

function initRotate(){
	if($('randomHeader')){
		rotator.numItems = $('randomHeader').select('img.randomHeader').length;
		rotator.timeout = window.setTimeout(rotator.autoFunc, rotator['interval']*0.33);
	}
}

//set up the functions that will be called at intervals
rotator.autoFunc = function(){
	rotator['currentItem'] = changeItem();
	rotator.timeout = window.setTimeout(rotator.autoFunc, rotator['interval']);
}

// function to change from one item to the next/previous, in a looping fashion	
function changeItem(){
	var currentEl = 'randomHeader'+rotator['currentItem'];
	var Next = rotator['currentItem']>=rotator['numItems'] ? 1 : rotator['currentItem']+1; 	
	var nextEl = 'randomHeader'+Next;		
    new Effect.Fade(currentEl, {duration: 2});
    new Effect.Appear(nextEl, {duration: 2});	
	rotator.count++;
	return Next;
}