/**********************************************
	Number based pagination
	
	This script takes any block level element,
	and a maximum height, and splits the element
	into pages. 
	
	These pages can be paginated through by
	the dynamically generated number links. 
	
	It adds the links to any subelements with a
	class of .number-pagination
	
	This script requires jQuery.
	
	Written by: 
		Adam Quaile, adamquaile@gmail.com
		www.62degrees.co.uk

**********************************************/

var pagination_class	= 'number-pagination';
var scroll_duration		= 1000;


/**
 * Makes a block level element dynamically scrollable.
 *
 * param selector The CSS style selector to choose the element. 
 * Currently only works with unique elements. Takes jQuery selectors.
 * param max_height integer The maximum height in pixels of the 
 * desired scrollable area.
**/
function dynamic_pagination(selector, controls_selector) {
		element = $(selector);
		// CSS set height is max
		max_height = element.height();
		//console.log(max_height)
		// Remove height: x px to get total height
		element.css('height', 'auto');
		height = element.height();
		//console.log(height);

		// Set up overflow so we can scroll
		element.css('overflow', 'hidden');
		
		// Put original height back
		element.css('height', max_height);
		
		pages = Math.ceil(height / max_height);
		if (pages > 1) {
			// Set up pagination
			var links = '';
			// Make links
			for (var i = pages - 1; i >= 0; i--) {
				links =	'<a href=\'#\' onClick=\'$("' + selector + '").scrollTo(' + 
												max_height*i + 
												', {duration:' + 
												scroll_duration + 
												'})\'>' + 
												(i+1) + 
												'</a>' + 
						links;
			};
			$(controls_selector).append(links);
		}
}