$(function($) {
	$.fn.easypagination = function( options ) {
		var settings = $.extend({
			pageNo:1,
			recordsPerPage:10,
			totalRecords:100
		},options);
		var page = (!settings.pageNo) ? 1 : settings.pageNo ;
		var page = (page == 0 ? 1 : page);
		var start = (parseInt(page)-1) * settings.recordsPerPage;
		var adjacents = "2";
		var prev = parseInt(page) - 1;
		var next = parseInt(page) + 1;
		var lastpage = Math.ceil(settings.totalRecords/settings.recordsPerPage);
		var lpm1 = parseInt(lastpage) - 1;   
		var pagination = "";
		if(lastpage > 1){
			pagination += "<div class='col-md-12 pagination'>";
			if (page > 1)
				pagination += "<a href=\"#Page="+(prev)+"\" class=\"pageClick\" page=\""+(prev)+"\">&laquo; Previous&nbsp;&nbsp;</a>";
			else
				pagination += "<span class='disabled'>&laquo; Previous&nbsp;&nbsp;</span>";
			
			if (lastpage < 7 + (adjacents * 2)){   
				for (counter = 1; counter <= lastpage; counter++)
				{
					if (counter == page)
						pagination += "<span class='current'>"+counter+"</span>";
					else
						pagination += "<a href=\"#Page="+(counter)+"\" class=\"pageClick\" page=\""+counter+"\">"+counter+"</a>";     
				}
			}  
			else if(lastpage > 5 + (adjacents * 2)){
				if(page < 1 + (adjacents * 2)){
					for(counter = 1; counter < 4 + parseInt((adjacents * 2)); counter++){
						if(counter == page)
							pagination += "<span class='current'>"+counter+"</span>";
						else
							pagination += "<a href=\"#Page="+(counter)+"\" class=\"pageClick\" page=\""+counter+"\">"+counter+"</a>";     
					}
					pagination += "...";
					pagination += "<a href=\"#Page="+(lpm1)+"\" class=\"pageClick\" page=\""+lpm1+"\">"+lpm1+"</a>";
					pagination += "<a href=\"#Page="+(lastpage)+"\" class=\"pageClick\" page=\""+lastpage+"\">"+lastpage+"</a>";   
				}
				else if(lastpage - (adjacents * 2) > page && page > (adjacents * 2)){
					pagination += "<a href=\"#Page=\"1\"\" class=\"pageClick\" page=\"1\">1</a>";
					pagination += "<a href=\"#Page=\"2\"\" class=\"pageClick\" page=\"2\">2</a>";
					pagination += "...";
					for(counter = page - adjacents; counter <= parseInt(page) + parseInt(adjacents); counter++){
						if(counter == page)
							pagination += "<span class='current'>"+counter+"</span>";
						else
							pagination += "<a href=\"#Page="+(counter)+"\" class=\"pageClick\" page=\""+counter+"\">"+counter+"</a>";     
					}
					pagination += "..";
					pagination += "<a href=\"#Page="+(lpm1)+"\" class=\"pageClick\" page=\""+lpm1+"\">"+lpm1+"</a>";
					pagination += "<a href=\"#Page="+(lastpage)+"\" class=\"pageClick\" page=\""+lastpage+"\">"+lastpage+"</a>";   
				}
				else{
					pagination += "<a href=\"#Page=\"1\"\" class=\"pageClick\" page=\"1\">1</a>";
					pagination += "<a href=\"#Page=\"2\"\" class=\"pageClick\" page=\"2\">2</a>";
					pagination += "..";
					for(counter = lastpage - (2 + parseInt((adjacents * 2))); counter <= lastpage; counter++){
						if(counter == page)
							pagination += "<span class='current'>"+counter+"</span>";
						else
							pagination += "<a href=\"#Page="+(counter)+"\" class=\"pageClick\" page=\""+counter+"\">"+counter+"</a>";     
					}
				}
			}
			if(page < counter - 1)
				pagination += "<a href=\"#Page="+(next)+"\" class=\"pageClick\" page=\""+(next)+"\">Next &raquo;</a>";
			else
				pagination += "<span class='disabled'>Next &raquo;</span>";
			
			pagination += "</div>";       
		}
		$(this).append(pagination);
	}
}(jQuery))