/**
 * Bureau 347 - Nicolas Ronsmans
 */

var backgroundConfig	=	{
								imagesList	:	[],
								delay		:	8 * 1000,
								index		:	0
							}

function backgroundInit(images)
{
	backgroundConfig.imagesList=images;
	setInterval('backgroundNextImage()',backgroundConfig.delay);
}

function backgroundNextImage()
{
	$('#background img').bind('load', backgroundResize).attr('src', backgroundConfig.imagesList[backgroundConfig.index]);
	backgroundConfig.index=(backgroundConfig.index>=(backgroundConfig.imagesList.length-1))?0:backgroundConfig.index+1;
}

function backgroundResize()
{
	$('#background img').css(
	{
		'width'			:	'100%',
		'height'		:	'auto'
	});

	if($('#background img').height() < $(window).height())
		$('#background img').css(
		{
			'width'		:	'auto',
			'height'	:	'100%'
		});
}

$(window).resize(function()
{
	backgroundResize();
});

$(document).ready(function()
{
	backgroundInit(backgroundImages);
	backgroundResize();
});
