var pager = {
	selectors: {
		page_links: ".b-paginate .b-paginate-page",
		active_cls: "active",
		controls_next: ".b-paginate .b-paginate-next",
		controls_prev: ".b-paginate .b-paginate-prev"
	},
	$container: null,
	current_page: 1,
	url_mask: null,
	init: function ($container, url_mask){
		this.$container = $container;
		this.$controls_next = $(this.selectors.controls_next).hide();
		this.$controls_prev = $(this.selectors.controls_prev).hide();
		this.pages_count = $(this.selectors.page_links).length; 
		this.url_mask = url_mask;
		$(this.selectors.page_links).click(function(pager){return function(){
			$(pager.selectors.page_links).removeClass(pager.selectors.active_cls);
			$(this).addClass(pager.selectors.active_cls);
			pager.load($(this).html());
		}}(this));
		this.$controls_prev.click(function(pager){return function(){
			if (pager.current_page > 1)
				$(pager.selectors.page_links + "." + pager.selectors.active_cls).prev().click();
		}}(this));				
		this.$controls_next.click(function(pager){return function(){
			if (pager.current_page < pager.pages_count)
				$(pager.selectors.page_links + "." + pager.selectors.active_cls).next().click();
		}}(this));				
		this.load(this.current_page);
	},
	load: function (page){
		this.current_page = page;
		if (this.current_page > 1)
			this.$controls_prev.show();
		else
			this.$controls_prev.hide();
		
		if (this.current_page < this.pages_count)
			this.$controls_next.show();
		else
			this.$controls_next.hide();
		
		$.get(this.url_mask.replace('_page_', page), function(pager, page){return function(content){
			if (pager.current_page == page)
			{
				pager.$container.html(content);
			}
		}}(this, page));		
	}
};
