var imgMax = 0;
var timerID;
var imgCount = 1;

$(function(){
	
	$("#bg li").each(function(){
		imgMax++;
		$(this).addClass("bg" + imgMax);
	});
	
	$(window).load(function() {
		if(imgMax == "1"){
			$('#bg li').fadeIn("slow");
		}else{
			$("#bg li.bg1").fadeIn("slow",setTimer);	
		}
	});
	
	
});

function setTimer(){
	setTimeout(transition,6000);
}

function transition(){
	if( imgCount >= imgMax ){
		imgCount = 1;
	}
	else {
		imgCount++;
	}

	$( '#bg li' ).each( function() {
		if($(this).css('display') != 'none'){
			$(this).fadeOut('slow');
		}
	});
	
	$('#bg li').eq(imgCount - 1).fadeIn("slow",setTimer);
};


