var bannerCount, bannerCurpos, scroller;

$(document).ready(function(){

	$(".scroll").scrollable({ circular: true });

	bannerCount = $(".scroll").data("scrollable").getItems().size();
	bannerCurpos = bannerCount;

	$("#banner_next").click(function() {
		clearTimeout(scroller);
		$(".scroll").data("scrollable").next();
		bannerCurpos = (bannerCurpos + 1 > bannerCount) ? 1 : bannerCurpos + 1;
		updateBannerPagination();
	});
	
	$("#banner_prev").click(function() {
		clearTimeout(scroller);
		$(".scroll").data("scrollable").prev();
		bannerCurpos = (bannerCurpos - 1 == 0) ? 3 : bannerCurpos - 1;
		updateBannerPagination();
	});
	
	$("#banner_pagination li a").click(function() {
		clearTimeout(scroller);
		gotonum = $(this).text();
		$(".scroll").data("scrollable").seekTo(gotonum);
		$("#banner_pagination li a.active").removeClass("active");
		$(this).addClass("active");
	});
	

	scroller = setTimeout('imageScroll();', 15000);

});

function imageScroll()
{
	$(".scroll").data("scrollable").next(800);
	bannerCurpos = (bannerCurpos + 1 > bannerCount) ? 1 : bannerCurpos + 1;
	updateBannerPagination();
	scroller = setTimeout('imageScroll();', 15000);
}

function updateBannerPagination()
{
	$("#banner_pagination li a.active").removeClass("active");
	$("#p" + bannerCurpos).addClass("active");
	if (bannerCurpos != 5)
	{
		$("#welcome_text img").fadeOut();
		$("#transformation_boxout").animate({marginTop:'0px'});
	}
	else
	{
		$("#welcome_text img").fadeIn();	
		$("#transformation_boxout").animate({marginTop:'-55px'});
	}
}
