CurrentImage = 1;
function NextImage(CountTab){
	CurrentImage = CurrentImage + 1;
	if(CurrentImage>=CountTab) CurrentImage = 0;
	return(CurrentImage);
}

function PrevImage(CountTab){
	CurrentImage = CurrentImage - 1;
	if(CurrentImage<0) CurrentImage = CountTab-1;
	return(CurrentImage);
}

function Next(CountTab){
	CurrentImage = NextImage( CountTab);
	$("#backgroundImage2").css("display", "block");
	$("#backgroundImage2").ezBgResize({
		img : TabImages[CurrentImage]
	});
	$("#backgroundImage3").fadeOut(100,function(){
		$("#backgroundImage").fadeOut(fade, function(){
			$("#backgroundImage").css("z-index","-3");
			$("#backgroundImage").css("display", "block");
			$("#backgroundImage").ezBgResize({
				img : TabImages[CurrentImage]
			});
			$("#backgroundImage3").fadeIn(100,function(){
				$("#backgroundImage").css("z-index","-1");
				$("#backgroundImage2").css("display", "none");
			})
		});
	});
		

}

function NextAgain(CountTab){
	Next(CountTab);
	timeoutID1 = window.setTimeout(function() { NextAgain(CountTab)},sleep);
}

function Prev(CountTab){
//	if (window.console) console.log("prev1 "+CurrentImage);
	CurrentImage = PrevImage( CountTab);
	$("#jq_ez_bg").fadeOut(fade,function(){
			$("#backgroundImage").ezBgResize({
				img : TabImages[CurrentImage],
			});
		$("#jq_ez_bg").fadeIn(300,function(){
		});
	});
}

$(window).load(function() {
})

$(document).ready(function() {
	NextAgain(CountTab);
	$("#backgroundImage").ezBgResize({
		img : TabImages[CurrentImage],
	});
	$(document).keydown(function (e) {
		if(e.which == 37){
			Prev(CountTab)
		}
		if(e.which == 39){
			Next(CountTab)
		}
	});
});

