window.addEvent('domready', function() {
	
	//the divs to be faded
	var faderDivs = $$('div.mainFeature');
	
	//if there are more than one child of the faderDiv parent then start fading
	if(faderDivs.length > 1) {
		//call the fading div with the time delay as an additional argument
		startFading(faderDivs[0], 5000);
	}
	
	//function to set up the fading
	function startFading(divShowing, time) {
		
		//get the next div,
		if(divShowing.getNext()) {
			var divNext = divShowing.getNext();
		}
		// if there is no next, get the first div.
		else {
			var divNext = faderDivs[0];
		}

		//start the fade with a delay specified as an argument, recurse the function so that it always runs.
		(function(){
		     new Fx.Tween(divShowing).start('opacity',0).chain( function(){
				//style has to be explicitly set here to prevent it appearing immediately the first time round.
				divNext.setStyle('opacity',0);
			 	new Fx.Tween(divNext).start('opacity',1);
				//get recursing
				startFading(divNext, time);
			 })
		}).delay(time);

	}

});
