$.fn.mypagination = function(totalProperty,opts){
	opts = $.extend({
		perPage:pageSize,
 
		callback:function(){
		}
	},opts||{});
		
	return this.each(function(){
		function numPages(){
			return Math.ceil(totalProperty/opts.perPage);
		}
 
		
		function selectPage(page){
			return function(){
				currPage = page;
				if (page<0) currPage = 0;
				if (page>=numPages()) currPage = numPages()-1;
				render();
				opts.callback(currPage+1);
			}
		}
		
		function render(){
			var html= '<div class="paginition">共<span class="cf00">'+numPages()+'</span>页 这是第[<span class="cf00">'+(currPage+1)+'</span>]页 ' ;
			if(currPage > 0){
				html=html+' <a class="page-first" href="javascript:void(0);">首页</a> '
						+' <a class="page-prev" href="javascript:void(0);">上一页</a>';
			}else{
				html=html+'<span class="page-first">首页</span> '
				+'<span class="page-prev">上一页</span>';
			}
			if (currPage < numPages()-1){
				html=html+' <a class="page-next" href="javascript:void(0);">下一页</a> '
				+'<a class="page-last" href="javascript:void(0);">尾页</a>';
			}else{
				html=html+'<span class="page-next">下一页</span> '
				+' <span class="page-last">尾页</span>';
			}
			html=html+'</div>';
			
			panel.empty();
			panel.append(html);
			if(numPages()!=1){
				if(currPage!=0 && currPage==(numPages()-1)){
					$(".page-first",panel)
						.bind('click',selectPage(0));	
					$(".page-prev",panel)
						.bind('click',selectPage(currPage-1));	
				}else if(currPage==0 && currPage!=(numPages()-1)){
					$(".page-next",panel)
						.bind('click',selectPage(currPage+1));	
					$(".page-last",panel)
						.bind('click',selectPage(numPages()-1));
				}else{
					$(".page-first",panel)
						.bind('click',selectPage(0));	
					$(".page-prev",panel)
						.bind('click',selectPage(currPage-1));
					$(".page-next",panel)
						.bind('click',selectPage(currPage+1));	
					$(".page-last",panel)
						.bind('click',selectPage(numPages()-1));
				}
			}
		}
		
		var currPage = 0;
		var panel = $(this);
		render();
 
	});
}