var paging = Class.create(); 
Object.extend(paging.prototype, { 

		pageVariable: 'curPage',
		numberFormat: '%n',
		showFirstLast: true,	// ¸ÇÃ³À½, ¸Ç ¸¶Áö¸·À¸·Î °¡´Â ¸µÅ©¸¦ ¸¸µé°ÍÀÎ°¡.
		amongStyle:' | ',
		thisPageStyle: 'font-weight: bold;color: #FF0000;',
		otherPageStyle:'',
		itemPerPage: 15,	// ¸®½ºÆ® ¸ñ·Ï¼ö
		pagePerView: 5,	// ÆäÀÌÁö´ç ³×ºñ°ÔÀÌ¼Ç Ç×¸ñ¼ö
		prevIcon: null,	// ÀÌÀüÆäÀÌÁö ¾ÆÀÌÄÜ
		nextIcon: null,	// ´ÙÀ½ÆäÀÌÁö ¾ÆÀÌÄÜ
		prevNaviIcon: null,	// ÀÌÀü³×ºñ°ÔÀÌ¼Ç ¾ÆÀÌÄÜ
		nextNaviIcon: null,	// ´ÙÀ½³×ºñ°ÔÀÌ¼Ç ¾ÆÀÌÄÜ
		firstIcon: null,	// Ã¹ÆäÀÌÁö·Î ¾ÆÀÌÄÜ
		lastIcon: null,	// ¸¶Áö¸·ÆäÀÌÁö ¾ÆÀÌÄÜ
		totalrow:null,//ÃÑ¼ö
		totalPage:null,//ÃÑÆäÀÌÁö
		currentPage:null,//ÇöÀçÆäÀÌÁö
		lastPageItems:null,//¸¶Áö¸·ÆäÀÌÁö °¹¼ö
		prevPage:null,//ÀÌÀüÆäÀÌÁö¹øÈ£
		nextPage:null,//´ÙÀ½ÆäÀÌÁö¹øÈ£
		prevNaviPage:null,//ÀÌÀüÆäÀÌÁö¹øÈ£
		nextNaviPage:null,//´ÙÀ½ÆäÀÌÁö¹øÈ£
		currentScale:null,//Çö³×ºñ°ÔÀÌ¼Ç À§Ä¡
		totalScale:null,//ÃÑ³×ºñ°ÔÀÌ¼Ç À§Ä¡
		lastScalePages:null,//¸¶Áö¸·³×ºñ°ÔÀÌ¼Ç À§Ä¡
		queryParams:null,

	initialize: function (totalrow){   
		
		//if(totalrow<1) totalrow=1;
		this.totalrow=totalrow;
		
		//ÇÑ±Û getÀ¸·Î Àü¼Û½Ã utf8ÈÄ encodeURI ¶§¹®¿¡ 
		//toQueryParams´Â decodeURIComponent ÇÒ¶§ utf8À» ÇÏ±â¶§¹®¿¡ ¹®Á¦¹ß»ý
		//this.queryParams=document.location.search.toQueryParams();
		this.queryParams=document.location.search.toQueryParams2();
		
		/*
		this.queryParams=document.location.search;
		this.queryParams.split(this.pageVariable);
		*/
	},
	calculate: function (){
		this.totalPage = Math.ceil(this.totalrow / this.itemPerPage);

		/*
		var tmp = this.queryParams.split(this.pageVariable+'=');

		if(tmp.length>1){
			
			this.currentPage=parseInt(tmp[1]);
			this.queryParams=tmp[0];

		}else{
			
			this.queryParams=tmp;

		}
		*/

		this.currentPage = parseInt(this.queryParams[this.pageVariable]);
		
		if (!this.currentPage) this.currentPage = 1;
		if (this.currentPage > this.totalPage) this.currentPage = this.totalPage;
		
		this.lastPageItems = this.totalPage % this.itemPerPage;
		
		//alert(this.currentPage);
		this.prevPage = this.currentPage-1;
		this.nextPage = this.currentPage+1;
		
		//this.seek = this.prevPage * this.itemPerPage;

		this.currentScale = parseInt(this.currentPage / this.pagePerView);

		if (this.currentPage % this.pagePerView < 1) this.currentScale--;
		
		this.totalScale = parseInt(this.totalPage / this.pagePerView);
		this.lastScalePages = this.totalPage % this.pagePerView;
		
		if (this.lastScalePages == 0) this.totalScale--;
		
		this.prevNaviPage = this.currentScale * this.pagePerView;
		this.nextNaviPage = this.prevNaviPage + this.pagePerView + 1;		
		
		

	},
	print: function(){
		var ss, se;
		var firstBtn = '';
		var lastBtn = '';
		var prevNaviBtn='';
		var nextNaviBtn = '';
		var prevBtn = '';
		var nextBtn = '';
		
		if(this.totalrow<1) return '';
		this.calculate();

		if (this.showFirstLast) {
			if (this.firstIcon) firstBtn = '<img src="'+this.firstIcon+'" border="0" align="absmiddle">';
			else firstBtn = '1...'; //'¢Ð';
			

				firstBtn = firstBtn.link(this.move("1"));
			if(this.currentPage==1) firstBtn="";
			
			if (this.lastIcon) lastBtn = '<img src="'+this.lastIcon+'" border="0" align="absmiddle">';
			else lastBtn = "..."+this.totalPage; //'¢Ñ';
			
			lastBtn = lastBtn.link(this.move(this.totalPage));
			if(this.currentPage==this.totalPage) lastBtn="";
		} else {
			firstBtn = lastBtn = '';
		}
		
		if (this.prevNaviIcon) prevNaviBtn ='<img src="'+this.prevNaviIcon+'" border="0" align="absmiddle">';
		else prevNaviBtn = '¢·';
		
		if (this.currentScale > 0) {
			prevNaviBtn = prevNaviBtn.link(this.move(this.prevNaviPage-this.pagePerView+1));
		}

		if (this.prevIcon) prevBtn ='<img src="'+this.prevIcon+'" border="0" align="absmiddle">';
		else prevBtn = '¢¸';
		if (this.currentPage > 1) {
			prevBtn = prevBtn.link(this.move(this.prevPage));
		}

		ss = this.prevNaviPage + 1;
		if ((this.currentScale >= this.totalScale) && (this.lastScalePages != 0)) se = ss + this.lastScalePages;
		else if (this.currentScale <= -1) se = ss;
		else se = ss + this.pagePerView;

		var navBtn = '';
		for(var i = ss; i<se; i++) {
			
			var pageText = this.numberFormat.replace(/%n/g,i);
			
			if(i!=ss) navBtn = navBtn + this.amongStyle;

			if (i == this.currentPage) {
				_btn = '<span style="'+this.thisPageStyle+'">'+pageText+'</span>';
			} else {
				_btn = '<a href="'+this.move(i)+'" style="'+this.otherPageStyle+'">'+pageText+'</a>'
			}
			navBtn+=_btn;
		}

		if (this.nextIcon) nextBtn ='<img src="'+this.nextIcon+'" border="0" align="absmiddle">';
		else nextBtn = '¢º';

		if (this.totalPage >= this.nextPage) {
			nextBtn = nextBtn.link(this.move(this.nextPage));
		}

		if (this.nextNaviIcon) nextNaviBtn ='<img src="'+this.nextNaviIcon+'" border="0" align="absmiddle">';
		else nextNaviBtn = '¢¹';
		
		if (this.totalScale > this.currentScale) {
			
				if (this.totalPage < this.nextNaviPage + this.pagePerView - 1) {
					nextNaviBtn = nextNaviBtn.link( this.move( this.totalPage));
				}else{
					nextNaviBtn = nextNaviBtn.link( this.move( this.nextNaviPage + this.pagePerView - 1));
				}
		}

		//return firstBtn+' '+prevBtn+navBtn+nextBtn+' '+lastBtn;		
		//return prevNaviBtn + ' ' + prevBtn + ' ' + firstBtn + navBtn + lastBtn + ' ' + nextBtn + ' ' + nextNaviBtn;
		return prevNaviBtn + ' ' + prevBtn + ' ' + firstBtn + ' ' + navBtn + ' ' + lastBtn + ' ' + nextBtn + ' ' + nextNaviBtn;
	},

	move:function (str) {
		
		var h = $H();
		
		var ret_txt='';

		this.queryParams[this.pageVariable]=str;
		
		for( keys in this.queryParams){
			if(ret_txt) ret_txt+="&";
			ret_txt = ret_txt+keys+"="+ this.queryParams[keys];
			h[keys] = this.queryParams[keys];
		}
		
		//alert(h.toQueryString());

		//alert(ret_txt);

		//return document.location.pathname+"?"+h.toQueryString();
		return document.location.pathname+"?"+ret_txt;

		/*
		var ret_txt =document.location.pathname+this.queryParams+'&'+this.pageVariable+'='+str;
		return ret_txt.replace(/&&/g,"&");
		*/
	}

}); 	
