jQuery(document).ready(function() {
	
	var allProjects = [];

	
	$('.project').each(function(index,domElement) {
			allProjects[index] = $(this); 
 	});
	
	for (var i = 0; i < allProjects.length; i++) {
		allProjects[i].find('img:first').show();		
	}
	
	
	$(".project").each(function (i) {
			allProjects[i].delegate(".imageBrowser a", "click", function(){
					$(this).parents('.project').find('img').hide();
					$(this).parents('.imageBrowser').find('a').removeClass('active');
					$(this).addClass('active');
					var selection = parseInt($(this).html())-1;
					//console.log(selection);
					var newImageSelector = $(this).parents('.project').find('img:eq('+selection+')');
					newImageSelector.show();
					return false;
			});
		
			allProjects[i].delegate("img", "click", function(){
					var imageId = parseInt($(this).attr("class").substr(1,2));
					var newImageId = 0;
					var images = $(this).parent().find('img');
					var imageCount = images.length;
					
					if (imageId<imageCount) {
						$(this).hide();
						$(this).next('img').show();
						newImageId = imageId;
					}
					else {
						$(this).hide();
						$(this).parent().find('img:first').show();
					}
					var links = [];
					links = $(this).parent().find('.imageBrowser a');
					links.removeClass('active');
					links.eq(newImageId).addClass('active');
					
					return false;
			});
		
	});
	
	
	
	//$("ul li:nth-child(2)").append("<span> - 2nd!</span>");


}); // jQuery(document).ready ends
