// Easing equation, borrowed from jQuery easing plugin
// http://gsgd.co.uk/sandbox/jquery/easing/
jQuery.easing.easeOutQuart = function (x, t, b, c, d) {
	return -c * ((t=t/d-1)*t*t*t - 1) + b;
};

jQuery(function( $ ){


	$('#g').serialScroll({
		target:'#sections',
		items:'li.diapo', // Selector to the items ( relative to the matched elements, '#sections' in this case )
		prev:'img.prev',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
		next:'img.next',// Selector to the 'next' button (absolute too)
		axis:'xy',// The default is 'y' scroll on both ways
		navigation:'#navigation li a',
		duration:300,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)

		onBefore:function( e, elem, $pane, $items, pos ){

			e.preventDefault();
			if( this.blur )
				this.blur();
		},
		onAfter:function( elem ){
			//'this' is the element being scrolled ($pane) not jqueryfied
		}
	});


});

/**
 *
 * @access public
 * @return void
 **/
function clic_vignette(index, nb_vignettes, alias){

	for(i = 1; i <= nb_vignettes; i++)
	{
		vignette = this.document.getElementById('vignette-' + i);

		if(i != index)
		{
			vignette.src = base_url + 'system/images/theme/' + alias + '-' + i + '.jpg';
		}
		else
		{
			vignette.src = base_url + 'system/images/theme/' + alias + '-' + i + '-actif.jpg';
		}
	}
}


var page = 1;

/**
 *
 * @access public
 * @return void
 **/
function clic_page(index, nb_pages){

	page = index;

	for(i = 1; i <= nb_pages; i++)
	{
		div_page = this.document.getElementById('page-' + i);

		if(i != index)
		{
			div_page.style.backgroundColor = '#f4a219';
			div_page.style.color = '#fff';
		}
		else
		{
			div_page.style.backgroundColor = '#fff';
			div_page.style.color = '#f4a219';
		}
	}
}

/**
 *
 * @access public
 * @return void
 **/
function prev_page(nb_pages){

	if (page > 1) {
		page --;
	}
	else{
		page = nb_pages;
	}

	clic_page(page, nb_pages);
}

function next_page(nb_pages){

	if (page < nb_pages) {
		page ++;
	}
	else{
		page = 1;
	}

	clic_page(page, nb_pages);
}
