var banner_timeout = null;
var banner_time_slot = 15000;
var banner_page = null;
var banner_counter = 0;

/*
$(document).ready(function() {
	startBannerAnimation();
});
//*/

function changeBanner() {
	$.get("pages/banner_selection.php", {page: banner_page, idx:++banner_counter}, function(html) {
		if(!first_page) {
			$('#banner_loading').css('width', '870px');
		}
		$("#banner_loading").fadeIn();
		$(".banner").fadeOut('slow', function() {
			var b = $(html);
			$(".banner").parent().html(b);
			b.css('opacity', '0');
			xmtr(b);
			$(document.body).bind('xmtr_loaded', function() {
				b.fadeTo('slow', 1, function() {
					b.css('opacity', '');
				});
				$("#banner_loading").fadeOut();
			});
		});		
	});
}

function nextBanner() {
	changeBanner();
	clearTimeout(banner_timeout);
	banner_timeout = setTimeout(nextBanner, banner_time_slot);
}

function startBannerAnimation() {
	clearTimeout(banner_timeout);
	banner_timeout = setTimeout(nextBanner, banner_time_slot);
	banner_counter = $("#banner_counter").val();
}

function stopBannerAnimation() {
	clearTimeout(banner_timeout);
}
