﻿

$(function()
{
	var index = 0;
	var items = $("#banner a.item");
	var upButton = $("#banner a.up-button");
	var downButton = $("#banner a.down-button");
	
	if (items.length <= 1)
	{
		upButton.css("display", "none");
		downButton.css("display", "none");
	}
	else
	{
		items.each(function(i)
		{
			if (this != items[index])
				$(this).css("top", "100%");
		});
		
		upButton.click(function(i)
		{
			newIndex = index + 1;
			
			if (newIndex > (items.length - 1))
				newIndex = 0;
			
			$(items[index])
				.css("bottom", null)
				.css("top", "0%")
				.animate({"top":"100%"}, "fast");
			
			$(items[newIndex])
				.css("top", null)
				.css("bottom", "100%")
				.css("display", "block")
				.animate({"bottom":"0%"}, "fast");
			
			index = newIndex;
		});
		
		downButton.click(function(i)
		{
			newIndex = index - 1;
			
			if (newIndex < 0)
				newIndex = (items.length - 1);
			
			$(items[index])
				.css("top", null)
				.css("bottom", "0%")
				.animate({"bottom":"100%"}, "fast");
			
			$(items[newIndex])
				.css("bottom", null)
				.css("top", "100%")
				.css("display", "block")
				.animate({"top":"0%"}, "fast");
			
			index = newIndex;
		});
	}
});


