var timeouts = [];
function BannerOnLoad(bannerId, bannerCount, rotatorCount, timeout)
{
	scroll(false, bannerId, false, timeout);
	if(rotatorCount<bannerCount)
		timeouts[bannerId] = setTimeout(function(){rotate(bannerId, timeout)}, timeout);
}
function scroll(prev, bannerId, restart, timeout) {
	if(restart)
		clearTimeout(timeouts[bannerId]);
	var allBanners = jQuery('.'+bannerId);
	var actual = jQuery("."+bannerId+":visible");
	var bannersSections = allBanners.length;
	var actualId = getActualId(bannerId);
	if (prev) {
		if (actualId == 0)
			actualId = bannersSections - 1;
		else actualId--;
	}
	else {
		if ((bannersSections - 1) == actualId)
			actualId = 0;
		else actualId++;
	}
	if(actual!=null)
		actual.hide();
	allBanners.eq(actualId).fadeIn(1000);
	if(restart)
		timeouts[bannerId] = setTimeout(function(){rotate(bannerId, timeout)}, timeout);
}
function rotate(bannerId, timeout) {
	scroll(false, bannerId, false, timeout);
	timeouts[bannerId] = setTimeout(function(){rotate(bannerId, timeout)}, timeout);
}

function getActualId(bannerId) {
	var allBanners = jQuery('.'+bannerId);
	var current = -1;
	for (var i = 0; i < allBanners.length; i++)
		if (allBanners.eq(i).is(':visible'))
		{
			current = i;
			break;
		}
	return current;
}
