$(document).ready(function() {

	var intro = $(".intro")[0];

	var imageCurrent = 1;
	var imageCount = 4;
	var imagePath = "url(/theme/sections/home/header_[n].jpg)";
	
	// preloader
	for(i=1; i <=4; i++){
		$('<img>').attr('src', '/theme/sections/home/header_'+i+'.jpg');
	}

	// :ATTN: do not use setInterval, is messed up on different browsers!
	// setInterval( function()
	// {
	// 	if( imageCurrent >= 4 ) imageCurrent = 1;
	// 
	// 	imageCurrent++;
	// 
	// 	intro.style.backgroundImage = imagePath.replace( '[n]', imageCurrent );
	// 
	// }, 4000);
	
	swap_intro_bg(1, 1000);
    
});

function swap_intro_bg( i , d )
{
	$(".intro").animate({ opacity: 1 }, d, "swing", function()
	{
		$(this).attr('style','background-image: url(/theme/sections/home/header_' + i + '.jpg);');
		
		i = ( i >= 4 ) ? 1 : i + 1;
		
		swap_intro_bg ( i , 16000 );
	});
}