
// instellingen
var backgrounds = {
	'tussentijd': 5		// hoe lang duurt het voor hij wisselt
};

function backgrounds_init()
{
	// starten. alle achtergronden worden absoluut geplaatst, linksboven in de div contentBackgrounds.
	// alles wordt onzichtbaar gemaakt behalve de eerste.

	if ($('contentBackgrounds'))
	{

		// pak afbeeldingen
		var i = $$('#contentBackgrounds img').setStyles({position:'absolute', top:0, left:0});
		
		if (i.length>1)
		{
			backgrounds.handles = [];
			// voor elke afbeelding een animatie handle maken en -behalve de eerste- de zichtbaarheid op 0 zetten.
			$each(i, function(el){
				backgrounds.handles.push(new Fx.Tween(el,{'property':'opacity'}));
			});
			for(i=1;i<backgrounds.handles.length;i++) backgrounds.handles[i].set(0);
		
			// hij is nu bij plaatje 0
			backgrounds.currentBackground = 0;
	
			// wisselfunctie aanzetten
			backgrounds.timer = backgrounds_switch.create({periodical:(backgrounds.tussentijd*1000)});
			backgrounds.timer();
		}
		
	}

}

function backgrounds_switch()
{
	// de huidige gaat naar 0, de nieuwe gaat naar 1
	var last = backgrounds.currentBackground;
	backgrounds.currentBackground++;
	if (backgrounds.currentBackground == backgrounds.handles.length) backgrounds.currentBackground = 0;

	backgrounds.handles[last].start(0);
	backgrounds.handles[backgrounds.currentBackground].start(1);

}

