var bannerList = [];

$(function () {
	var bannerIndex = 0, bannerIntervalID = null;

	if (bannerList.length > 1) {
		$("#banner-move-left").show().click(previousBanner);
		$("#banner-move-right").show().click(nextBanner);
		$("#page").css("overflowX", "hidden");
		
		delaySwitchBanner();
	}

	function previousBanner() {
		switchBanner(-1);
		delaySwitchBanner();
	}
	function nextBanner() {
		switchBanner(1);
		delaySwitchBanner();
	}
	function delaySwitchBanner() {
		if (bannerIntervalID !== null)
			window.clearInterval(bannerIntervalID);
		bannerIntervalID = window.setInterval(nextBanner, 10000);
	}
	function switchBanner(increment) {
		if (typeof increment == "undefined") increment = 1;
		bannerIndex += increment;
		
		if (increment > 0) {
			if (bannerList.length <= bannerIndex) bannerIndex = 0;
		} else {
			if (bannerIndex < 0) bannerIndex = bannerList.length - 1;
		}
		$("#banner-block").animate({
			   "left": "-1500px",
			"opacity": 0
		}, 1000, function () {
			$("#banner-block").css("left", (screen.width ? (screen.width + 100) + "px" : "2000px"));
			$("#banner-picture").attr("src", baseUri + "/data/" + bannerList[bannerIndex][0])
			                    .attr("width", bannerList[bannerIndex][1][0])
			                    .attr("height", bannerList[bannerIndex][1][1]);
			$("#banner-content").html(bannerList[bannerIndex][2]);
			
			$("#banner-block").animate({
				   "left": "0px",
				"opacity": 1
			}, 800);
		});
		/*
		$("#banner-block").fadeOut(500, function () {
			$("#banner-picture").attr("src", baseUri + "/data/" + bannerList[bannerIndex][0])
			                    .attr("width", bannerList[bannerIndex][1][0])
			                    .attr("height", bannerList[bannerIndex][1][1]);
			$("#banner-content").html(bannerList[bannerIndex][2]);
			
			$("#banner-block").delay(500).fadeIn(800);
		});
		*/
	}
});
