function ReadCookie(name)
{
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
	    var c = ca[i];
	    while (c.charAt(0)==' ') c = c.substring(1,c.length);
	    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function WriteCookie(name, value, date) 
{
	if (date != null) {
		date = new Date(date);
		document.cookie = name + "=" + value + "; expires=" + date.toGMTString() + "; path=/";
	}
	else {
		document.cookie = name + "=" + value + "; path=/";
	}
}

var fastFactIndex = ReadCookie("ffi")==null ? 0 : parseInt(ReadCookie("ffi"));

function ShowFastFact (delta) 
{
	var max = $("#FASTFACTS ul li").length;
	if (delta != null) fastFactIndex += delta;

	if (fastFactIndex < 0) fastFactIndex = max - 1;
	if (fastFactIndex >= max) fastFactIndex = 0;
	
	$("#FASTFACTS ul li").hide();
	$("#FASTFACTS ul li:nth-child("+(fastFactIndex+1)+")").show();

	WriteCookie("ffi", fastFactIndex+1);
}
