// JavaScript Document

var i = -1;

var endCap = 0;




jQuery(document).ready(function() {


	//alert('hello');


	//$('div#target').css('backgroundImage', 'url(/v4/images/bn-immanuel.png)');
	
	
	// this each loop counts the total lis
	jQuery('ul#gallery li').each(function(j) {
	
			//alert(j);
			endCap = j;
	
	});

	
	//alert(endCap);
	
	
	function changeMyPic() {
		
		// i = i+1;
		
		i++;
		
		if(i > endCap) {
		
			i = 0;
		
		}
		
		
		
		/*
		"ul li:nth-child("    .     i    .     ")"
		
		"ul li:nth-child(2)"
		
		"i am happy"
		
		"i am "  +  "happy"
		*/
		
		
		
		var k = i + 1; 
		
		var newImage = jQuery("ul li:nth-child(" + k + ")").find('img').attr('src');
		
		var urlImage = 'url(' + newImage + ')';
		
		
		
		
		
		jQuery('div#target').fadeOut(4000, function(){
		
		
				jQuery('div#target').css('backgroundImage', urlImage).fadeIn(4000);
		
		
		});
		
		
		//alert(i + " -- " + newImage);
		
		
	
	}
	

	//changeMyPic();
	
	// this calls the function every 8 seconds
	setInterval(changeMyPic, 8000);
	

});



// example of a function // how to define a function
function sum(a, b, d){
 
 	var c = a + b - d;
	
 	return c;
 
 
}
 
 var q = sum(2,2,1);
 
// alert(q);