// JavaScript Document

var bgStandardWidth = 980;
var bgStandardHeight = 650;

var current;
var loaded = 0;
var total;
var fallback = true;

function initSlideshow()
{
	total = $("#background > img").length;
	$("#background > img").css('left', '-' + bgStandardWidth + 'px');
	$("#background").css('left', '0');
	current = Math.floor(Math.random() * total);
	showPicture(current, 0);
	window.setInterval("showNext()", 5000);
}
	
function fallbackInit()
{
	if (fallback == true)
		realInit();
}

function showPicture(number, duration)
{
	var prevImg = $('#background img:nth-child(' + (((current + total - 1) % total) + 1) + ')');
	var currImg = $('#background img:nth-child(' + (number + 1) + ')');
	prevImg.css('left', '0px');
	prevImg.animate({ left: '-' + bgStandardWidth + 'px' }, { queue: false , duration: duration });
	currImg.css('left', bgStandardWidth + 'px' );
	currImg.animate({ left: '0px' }, { queue: false , duration: duration });
}
	
function showNext()
{
	current = ++current % total;	
	showPicture(current, 500);
}
