var nouvelles_par_page = 3;
var nb_nouvelles;
var page_courante;
var nb_pages;


$(document).ready(function(){

  $('a.fancy').fancybox({
		'width'					: 600,
		//'height'				: '75%',
		'autoScale'     : false,
		'transitionIn'	: 'none',
		'transitionOut'	: 'none',
		'type'					: 'iframe'
	});
	
	nb_nouvelles = $('#nouvelles ul').children().size();  
	nb_pages = Math.ceil(nb_nouvelles/nouvelles_par_page); 
	
	if(nb_pages==1)
	{
		$('a.apres').hide();
		$('a.avant').hide();
	}
	page_courante = 1;

	//hide all the elements inside content div
	$('#nouvelles ul').children().hide();

	$('a.apres').click(function(){apres()});
	$('a.avant').click(function(){avant()});
	
	go_to_page(page_courante);	
});


function apres(){
	if(page_courante > 1)
	{
		$('a.avant').show();
		page_courante--;
		go_to_page(page_courante);
	}	
}

function avant(){

	if(page_courante != nb_pages)
	{
		$('a.apres').show();
		page_courante++;
		go_to_page(page_courante);
	}
}
function go_to_page(page_num){
	if(page_courante == 1) $('a.apres').hide();
	else if(page_courante == nb_pages) $('a.avant').hide();

	//get the element number where to start the slice from
	start_from = (page_courante-1) * nouvelles_par_page;

	//get the element number where to end the slice
	end_on = start_from + nouvelles_par_page;

	//hide all children elements of content div, get specific items and show them
	$('#nouvelles ul').children().hide().slice(start_from, end_on).show();
	
}

