$(document).ready(function() {

	// removes scrollbar for images
	$("body").removeClass("no-script");
	
	// Checks there are images in the list
	if ((total = $('#screen li').size())>1) {
	
		//
		function update_nav (clicked_on) {
			$('#browse li a').removeClass("current");
			$('#browse li:eq('+clicked_on+') a').addClass("current");
		}
	
		// Shows the first image to start
		$("#screen li").hide();
		$("#screen li:first-child").show();
		
		// Creates a bulleted list for navigation. Matches the number of images included in #screen.
		$("#introduction").after("<ol id=\"browse\">\n</ol>");
		$("#screen li").each(function() {
			
			$("#browse").append("<li><a href=\"#\">&bull;</a></li>");
		});
		$("#browse li:nth-child(1)").addClass("first");
		$("#browse li:nth-child(1) a").addClass("current");
		
		$("#screen li").click( function() {
			
			update_nav(clicked_on = $("#screen li").index($(this)) +1);
			
			$("#screen li:nth-child("+clicked_on+")").fadeOut(600);
			$("#screen li").hide();
			
			if (clicked_on != total) { $(this).next().fadeIn(700); }
			else {
				$("#screen li:first-child").fadeIn(700);
				$("#browse li:nth-child(1) a").addClass("current");
			}
		});
		 
		$("#browse li").click( function() {
		 
			update_nav(clicked_on = $("#browse li").index($(this)));
			$("#screen li").hide();
			$('#screen li:eq('+clicked_on+')').fadeIn(700);			
		});
	}
	else if (!total)
	{ alert("Please make sure there are images in the page"); }
});
