var start_pic = 3;
var number_pic = 4;


$(document).ready(function(){

   	current_loop = setTimeout(play,5000);
   	
});

function play() {
	
   	clearTimeout(current_loop);
   	
   	for(var i = 0 ; i < start_pic ; i++) {
		$("#bg" + i).show();
	}
		
	var prevPic = start_pic - 1;
	if(prevPic < 0) {
		prevPic = 3;
	}
	
	if(prevPic != 3) {
		$("#bg" + start_pic).fadeOut(2000);		
	}
	else {
		$("#bg" + prevPic).fadeIn(2000);
	}
	
	start_pic = start_pic - 1;
	if(start_pic < 0) {
		start_pic = 4;
	}
	
   	current_loop = setTimeout(play,5000);
}
