
var current = 0;
var fadeCover = null;
var contentPhoto = null;
var photoDescrip = null;
var contentDescrip = null;

function rotateHeader(pe)
{
	contentPhoto.src = headerImages[current].src;
	contentDescrip.update(headerImages[current].title);
	
	if(++current >= headerImages.length)
	{
		current = 0;
	}

	fadeCover.setStyle({ background: 'url('+headerImages[current].src+') no-repeat'});
	fadeCover.setStyle({ opacity: 0, display: 'block' }).fade({ from: 0, to: 1.0, duration: 3.0 });
	
	photoDescrip.update(headerImages[current].title);
	photoDescrip.setStyle({ opacity: 0, display: 'block' }).fade({ from: 0, to: 1.0, duration: 3.0 });
}

function preloadImages()
{
	for(var i=0; i<headerImages.length; i++)
	{
		window['image'+i] = new Image();
		window['image'+i].src = headerImages[i].src;
	}
}

function initFader() {
	fadeCover = $('fade-cover');
	contentPhoto = $('content-photo-img-image');
	contentDescrip = $('content-photo-description');
	
	var bgColor = contentDescrip.getStyle('backgroundColor');
	
	photoDescrip = new Element('p', { className: 'content-photo-description' });
	photoDescrip.setStyle({ display: 'block', backgroundColor: bgColor }).update(contentDescrip.innerHTML);
	
	$('content-photo').appendChild(photoDescrip);
	
	preloadImages();
	
	new PeriodicalExecuter(rotateHeader, rotationSpeed);
}

Event.observe(window, 'load', initFader);
