var currentlatestupdates = undefined;
var oldlatestupdates = undefined;
var latestupdatesanim = false;
var fromFirst2 = false;
function showNextLatestupdates() {
	if (latestupdatesanim) return;
	if (currentlatestupdates == undefined) {
		$("#latestnewscontent .newsitem").css("top","300px");
		currentlatestupdates = $("#latestnewscontent .newsitem:first-child");
	} else {
		if ($(currentlatestupdates).attr('id') == $("#latestnewscontent .newsitem:last-child").attr('id'))
			{
				oldlatestupdates = currentlatestupdates;
				latestupdatesanim = true;
				$(currentlatestupdates).animate({top: -300},"slow", function() {
					$(oldlatestupdates).css("top","300px");
					latestupdatesanim = false;
					currentlatestupdates = undefined;
					showNextLatestupdates();
				});
				currentlatestupdates = undefined;
				return;
			}
		oldlatestupdates = currentlatestupdates;
		latestupdatesanim = true;
		$(currentlatestupdates).animate({top: -300},"slow", function() {
			$(oldlatestupdates).css("top","300px");
			latestupdatesanim = false;
		});
		currentlatestupdates = $(currentlatestupdates).next();
	}
	
	latestupdatesanim = true;
	$(currentlatestupdates).animate({top: 0},"slow", function() { latestupdatesanim = false; } );
}

function showPrevLatestupdates() {
	if (latestupdatesanim) return;
	if (currentlatestupdates == undefined) {
		$("#latestnewscontent .newsitem").css("top","300px");
		currentlatestupdates = $("#latestnewscontent .newsitem:first-child");
	} else {
		if ($(currentlatestupdates).attr('id') == $("#latestnewscontent .newsitem:first-child").attr('id')) 
		{
			oldlatestupdates = currentlatestupdates;
				latestupdatesanim = true;
				$(currentlatestupdates).animate({top: 300},"slow", function() {
					$(oldlatestupdates).css("top","300px");
					latestupdatesanim = false;
					currentlatestupdates = $("#latestnewscontent .newsitem:last-child");
					fromFirst2 = true;
					showPrevLatestupdates();
				});
			return;
		}
		
		if(fromFirst2){ fromFirst2 = false;}else
		{
		oldlatestupdates = currentlatestupdates;
		latestupdatesanim = true;
		$(currentlatestupdates).animate({top: 300},"slow", function() {
			$(oldlatestupdates).css("top","300px");
			latestupdatesanim = false;
		});
		currentlatestupdates = $(currentlatestupdates).prev();
		}
	}
	$(currentlatestupdates).css("top","-300px");
	latestupdatesanim = true;
	$(currentlatestupdates).animate({top: 5},"slow", function() { latestupdatesanim = false; });
}





var currentfood = undefined;
var oldfood = undefined;
var foodanim = false;
function showNextFood() {
	if (foodanim) return;
	if (currentfood == undefined) {
		$("#latestfoodcontent .newsitem").css("top","300px");
		currentfood = $("#latestfoodcontent .newsitem:first-child");
	} else {
		if ($(currentfood).attr('id') == $("#latestfoodcontent .newsitem:last-child").attr('id')) return;
		oldfood = currentfood;
		foodanim = true;
		$(currentfood).animate({top: -300},"slow", function() {
			$(oldfood).css("top","300px");
			foodanim = false;
		});
		currentfood = $(currentfood).next();
	}
	
	foodanim = true;
	$(currentfood).animate({top: 0},"slow", function() { foodanim = false; });

	if ($(currentfood).attr('id') == $("#latestfoodcontent .newsitem:first-child").attr('id')) {
		$("#food_u").attr('src','images/up_off.png');
	} else {
		$("#food_u").attr('src','images/up_on.png');
	}
	
	if ($(currentfood).attr('id') == $("#latestfoodcontent .newsitem:last-child").attr('id')) {
		$("#food_d").attr('src','images/down_off.png');
	} else {
		$("#food_d").attr('src','images/down_on.png');
	}
}

function showPrevFood() {
	if (foodanim) return;
	if (currentfood == undefined) {
		$("#latestfoodcontent .newsitem").css("top","300px");
		currentfood = $("#latestfoodcontent .newsitem:first-child");
	} else {
		if ($(currentfood).attr('id') == $("#latestfoodcontent .newsitem:first-child").attr('id')) return;
		oldfood = currentfood;
		foodanim = true;
		$(currentfood).animate({top: 300},"slow", function() {
			$(oldfood).css("top","300px");
			foodanim = false;
		});
		currentfood = $(currentfood).prev();
	}
	$(currentfood).css("top","-300px");
	foodanim = true;
	$(currentfood).animate({top: 5},"slow", function() { foodanim = false; });

	if ($(currentfood).attr('id') == $("#latestfoodcontent .newsitem:first-child").attr('id')) {
		$("#food_u").attr('src','images/up_off.png');
	} else {
		$("#food_u").attr('src','images/up_on.png');
	}
	
	if ($(currentfood).attr('id') == $("#latestfoodcontent .newsitem:last-child").attr('id')) {
		$("#food_d").attr('src','images/down_off.png');
	} else {
		$("#food_d").attr('src','images/down_on.png');
	}
}



var currentfeatured = undefined;
var oldfeatured = undefined;
var featuredanim = false;
var fromFirst = false;
function showNextFeatured() {
	if (featuredanim) return;
	if (currentfeatured == undefined) {
		$("#latestfeaturedcontent .newsitem").css("top","300px");
		currentfeatured = $("#latestfeaturedcontent .newsitem:first-child");
	} else {
		if ($(currentfeatured).attr('id') == $("#latestfeaturedcontent .newsitem:last-child").attr('id'))
			{
				oldfeatured = currentfeatured;
				featuredanim = true;
				$(currentfeatured).animate({top: -300},"slow", function() {
					$(oldfeatured).css("top","300px");
					featuredanim = false;
					currentfeatured = undefined;
					showNextFeatured();
				});
				currentfeatured = undefined;
				return;
			}
		oldfeatured = currentfeatured;
		featuredanim = true;
		$(currentfeatured).animate({top: -300},"slow", function() {
			$(oldfeatured).css("top","300px");
			featuredanim = false;
		});
		currentfeatured = $(currentfeatured).next();
	}
	
	featuredanim = true;
	$(currentfeatured).animate({top: 0},"slow", function() { featuredanim = false; } );
}

function showPrevFeatured() {
	if (featuredanim) return;
	if (currentfeatured == undefined) {
		$("#latestfeaturedcontent .newsitem").css("top","300px");
		currentfeatured = $("#latestfeaturedcontent .newsitem:first-child");
	} else {
		if ($(currentfeatured).attr('id') == $("#latestfeaturedcontent .newsitem:first-child").attr('id')) 
		{
			oldfeatured = currentfeatured;
				featuredanim = true;
				$(currentfeatured).animate({top: 300},"slow", function() {
					$(oldfeatured).css("top","300px");
					featuredanim = false;
					currentfeatured = $("#latestfeaturedcontent .newsitem:last-child");
					fromFirst = true;
					showPrevFeatured();
				});
			return;
		}
		
		if(fromFirst){ fromFirst = false;}else
		{
		oldfeatured = currentfeatured;
		featuredanim = true;
		$(currentfeatured).animate({top: 300},"slow", function() {
			$(oldfeatured).css("top","300px");
			featuredanim = false;
		});
		currentfeatured = $(currentfeatured).prev();
		}
	}
	$(currentfeatured).css("top","-300px");
	featuredanim = true;
	$(currentfeatured).animate({top: 5},"slow", function() { featuredanim = false; });
}

$(document).ready(
	function() {
		showNextLatestupdates();
		setInterval( "showNextLatestupdates()", 5000 );
		showNextFood();
		showNextFeatured();
		setInterval( "showNextFeatured()", 5000 );
	}
);

