// TODO: check if IE blows up with this script

if (!fannedImage)	// should be set by inline js
{
	var fannedImage = 1;
}

$(document).ready(function() {
	var fannedImages = [];
	
	/* preload */
	for(i = 1; i <= 4; i++)		// 4 images (fanned1.png .. fanned4.png); TODO: php->smarty->inline js->here (worth it?)
	{
		thisImg = "/img/fanned" + i + ".png";
		$("<img />")
			.attr("src", thisImg)
			.load(function() {
				fannedImages[fannedImages.length] = thisImg;
			});
	}
	
	if (($.browser.msie && parseFloat($.browser.version.substr(0,3)) < 7)
		||
		(navigator.userAgent.indexOf("iPhone") > 0 || navigator.userAgent.indexOf("iPod") > 0))
	{
		var skipFannedRotation = true;
	}
	
	if (!skipFannedRotation)
	{
		$.timer(5000, function() {
			if (++fannedImage > fannedImages.length)
			{
				fannedImage = 1;
			}
			$("#fanned").fadeTo(1500, 0, function() {	/* fadeOut chokes the page as it hides the element, fadeTo just changes the opacity */
				$("#fanned").css("background-image", "url(/img/fanned" + fannedImage + ".png)");
			});
			$("#fanned").fadeTo(1500, 1);
		});
	}
});