// init vars
var i = [];
var total = 0;
var count = 0;

$(document).ready(function() {
	
	$('#bgImages li IMG').each(function(index) {
		//i.push(x);
		i[index] = [$(this).attr('src'),$(this).attr('title')];
		//alert(index + ': ' + $(this).attr('title'));
		$("#flashbkg").css('background-image', $(this).attr('src'));
	});
	
	setImage(0);
	
	/* 	
		DISABLED 2011-07-04
		uncomment to enable video initialisation.
	*/
	//initVideo();
});

function setImage(img) {
	if (img == null) img=0;
	total = i.length -1;		
	//alert(img);
	var imgurl = 'url(' + i[img][0] + ')';
	
	$("#flashbkg").css({opacity:0});
	$("#flashbkg").css('background-image', imgurl );
	$("#title H2").text(i[img][1]);
	//alert(i[img]);
	$('#flashbkg').animate({
	opacity: 1
	}, 1500, function() {
		if(count>=total) {
			count = 0;
		} else {
			count++; 
			//alert(count);
		} 
		window.setTimeout(function() {setImage(count)}, 5000);
	});
}

function initVideo() {
	flowplayer("flashcontent", {src: "../_template/flash/flowplayer-3.2.7.swf", wmode: 'opaque'},  {
		playlist: [
			//splash image
			{
				url: '/_template/img/home/poster.jpg', 
				scaling: 'orig'
			},  
			// autoPlay is set to false the splash screen will be shown
			{
				url: '/_template/flash/promac.flv', 
				autoPlay: false, 
				// video buffered when splash screen is visible
				autoBuffering: true
			}
		]
	});	
}
