//-----------
//PAGINATION

//setup pagination
function setupPagination(id) {
	
	//only run once
	if ($(id).setup == true) return;

	//configuration options
	$(id).setup = true;
	$(id).offset = $$('#'+id+' .item0')[0].getLeft() - $(id).getLeft();
	$(id).i = 0;
	
	//increase padding of last item
	var tag = $$('#'+id+' .item0')[0].getTag();
	var last = $(id).getElements(tag).getLast();
	//last.setStyle('padding-bottom', $(id).offset);

}

//get scroll setting
function getPaginationScroll(id) {
	return new Fx.Scroll(id, {
		wait: false,
		duration: 500,
		offset: {x:-$(id).offset, y: -10}
	});
}

//the back arrow
function pageBack(id, d) {
	setupPagination(id);
	pageChange(id, $(id).i - d);

}

//the front arrow
function pageNext(id, d) {
	setupPagination(id);
	pageChange(id, $(id).i + d);
}


//go to a certain page
function pageChange(id, i) {
	setupPagination(id);

	//get the target element, abort if it's not found
	var el = $$('#'+id+' .item'+i)[0];
	if (!el) return;

	//get the scroll setup
	var scroll = getPaginationScroll(id);
	
	//run scroll
	$(id).i = i;
	scroll.toElement(el);
	
	//clear all page "on" states
	//$$('#controls_'+id+' a').removeClass('on');
	
	//set the page counter to the on position for the current page
	//$$('#controls_'+id+' .item'+i)[0].addClass('on');
	
}

//--------------------
