var items_per_page = 4;

function pageselectCallback(page_index, jq){
	var thumbs = $(".calendarThumbs .thumbContainer");
	// hide all
	thumbs.each(function() { $(this).hide(); });
	
	// show specific in pagingated area
	var dex = page_index * items_per_page;
	for(var i = 0; i < thumbs.length && i < items_per_page; i++, dex++)
	{
		$(thumbs[dex]).show();
	}
	
	return false;
}

function showEvent(id)
{
	// show event
	$(".calendarEvent").hide();
	$(".calendarEvent_" + id).show();
	
	// hightlight thumb
	$(".calendarThumbs .thumbContainer img").removeClass("calendarThumbOn");
	$("#thumb_" + id + " img").addClass("calendarThumbOn");
}

$(function() {
	var opts = {
		items_per_page: items_per_page,
		num_display_entries: 3,
		prev_text:"prev &laquo;",
		next_text:"next &raquo;",
		ellipse_text:"...",
		prev_show_always:false,
		next_show_always:false,
		callback: pageselectCallback
	}
	
	$("#pagination").pagination($(".calendarThumbs .thumbContainer").length, opts);	
	
	$(".calendarThumbs .thumbContainer").click(function() {
		var id = $(this).attr("id").split("_")[1];
		showEvent(id);
	});
	
	showEvent($($(".thumbContainer")[0]).attr("id").split("_")[1]);
});
