$(document).ready(function(){
	$(".project").each(function(){
	    var target= $(this);
		var projects = $(".project_detail");
		
		projects.each(function(i) {
			var proj = $(this);
			var id = proj.attr("id");
			
			$(".project_selector", target).append(
				$("<li>"+(i+1)+"</li>")
				.click(function() {
					$(".project_selector li", target).removeClass("active");
					$(this).addClass("active");
					
					var details = $("#"+id);
					$(".project_details", target).empty().append(details.clone(true));
					
					$(".project_details .thickbox[rel=pics]", target).attr("rel", "active_pics");
					
					var prev = i-1;
					if (prev < 0) prev = projects.length-1;
					$(".go_left", target).unbind("click").click(function() {
						$($(".project_selector li", target).get(prev)).click();
					});
					
					var next = i+1;
					if (next >= projects.length) next = 0;
					$(".go_right", target).unbind("click").click(function() {
						$($(".project_selector li", target).get(next)).click();
					});
				})
			);
		});
	
		$(".project_selector li:first", target).click();
	});
});
