
$(function() {		
	
	formatandpaginate();
	
	$("#publist div.publication h3").click(function(){
		location.href = $(this).nextAll("a.learn_more").attr("href");	
	});

});

function pageTo(x){
	//$("div.pagination a").removeClass("selected").eq(x).addClass("selected");
	$(".pagination").each(function(){
			$(this).find("a").removeClass("selected").eq(x).addClass("selected");
	}); 
	var y = 4*x; x = 12*x;
	$("#publist div.publication:visible, #publist div.pubdivider:visible").fadeOut(500,function(){
		$("#publist div.pubdivider").slice(y, y+4).show();
		$("#publist div.publication").slice(x,x+12).fadeIn(500);	
	});
	return false;
}

function formatandpaginate(){
// even up the lines by adding in a full width div after every 3 pubs
	$("#publist div.publication:nth-child(3n)").after("<div class='pubdivider'>&nbsp;</div>");
	
	// only show the first 12 pubs, and create links to the rest
	var x = $("#publist div.publication").length + 1, y=0;
	if(x > 12){
		$("#publist div.publication:gt(11)").hide();
		var $jumplinks = $(".pagination");
		x = Math.floor(x/12);
		/* y = x < 4 ? x : 4;  // <- optional code for limiting numbers shown to 4  */
		for(var i=0;i<=x;i++){
			if (i > 0) $jumplinks.append(" | ");
			$jumplinks.append("<a onclick='pageTo("+i+");'>" + (i+1) + "</a>");
		}
		//$("div.pagination a:first").addClass('selected');
		$("#publist div.pubdivider:visible").fadeOut(0,function(){
			$("#publist div.pubdivider").slice(0, 4).show();	
		});
		$(".pagination").each(function(){
			$(this).find("a:first").addClass('selected');
		}); 
	}
}

  	



