function preloadImg() {
	for (var i = 0; i < images.length; i++) {
    var im = new Image();
    im.src = images[i];
  }
	current_img = 0;
}

function slideShow() {
//	images = new Array();
	for (var i = 0; i < images.length; i++) {
		images[i] = '/images/header/' + images[i] + '.jpg';
	}
	preloadImg();
	var d = new Element('div', { 'id': 'image-fade', 'style': 'height:236px; width:800px; z-index: 200;' });
	$('header-2').appendChild(d);
	
	new PeriodicalExecuter(changeImg, 5);
}

function changeImg() {
	if (current_img == images.length - 1) { current_img = 0; }
	else { current_img++; }
	$('header-2').style.background = "url('" + images[current_img] + "')";
		new Effect.Fade('image-fade', { 
			duration: 2, 
			fps: 50,
			queue: 'end',
			afterFinish: function() {
				$('image-fade').style.background =  "url('" + images[current_img] + "')";
				$('image-fade').show();
			}
		}	)	
}

window.onload = function() {
	if (images.length > 0) slideShow();
}

