/**
 * 페이징
 * @param {Object} totalPage 전체페이지
 * @param {Object} thisPage 현재페이지
 * @param {Object} conf 환경설정
 */
function jjGetPaging(totalPage, thisPage, conf) {
	if(!totalPage || totalPage<1) totalPage = 1;
	if(!thisPage  || thisPage<1)  thisPage  = 1;
	if(!conf) {
		conf = [
			'<b>__HERE__</b> ',
			'<a href="__URL____HERE__">__HERE__</a> ',
			'<a href="__URL____HERE__">&gt;</a> ',     // <
			'<a href="__URL____HERE__">&lt;</a> ',     // >
			'<a href="__URL____HERE__">&gt;&gt;</a> ', // <<
			'<a href="__URL____HERE__">&lt;&lt;</a> '  // >>
		];
	}
	
	totalPage = parseInt(totalPage);
	thisPage  = parseInt(thisPage);
	
	toUrl = document.location.href.toString();
	tmp   = toUrl.split("?");
	if(tmp[1]) {
		tmp[1] = tmp[1].replace(/&?page=[0-9]*/, '');
		toUrl = tmp[0] + "?" + tmp[1];
	} else {
		toUrl = tmp[0] +"?";
	}
	toUrl += "&page=";
	
	//alert(thisPage);
	/*
	var start = thisPage - 3;
	var end   = thisPage + 6;
	
	
	if(start<1) {
		end  += (start-1)*-1;
		start = 1;
	}
	if(end>totalPage) {
		start -= (end+1) - totalPage;
		end = totalPage;
		if(start<1) start = 1;
	}
	*/
	
	var start = 1;
	var end = 10;

	var temp1 = Math.ceil(thisPage/10)-1;
	//alert(temp1);
	
	if (temp1 == 0)	{
		start = 1;
	}else{
		start = temp1 * 10 + 1;
	}
	
	if (Math.ceil(thisPage/10)*10 > totalPage)	{
		end = totalPage;
	}else{
		end = Math.ceil(thisPage/10)*10 ;
	}
	
	//alert(start);	alert(end);
	
	
	var html = "<a class=\"page\" href=\"\"></a>";
	
	if(start-1>1) html += conf[4].replace(/__HERE__/ig, 1);
	if(start>1)   html += conf[2].replace(/__HERE__/ig, start-1);
	
	for(var i=start; i<=end; i++) {
		if(i==thisPage) html += conf[0].replace(/__HERE__/ig, i);
		else            html += conf[1].replace(/__HERE__/ig, i);
	}

	if(totalPage>end)   html += conf[3].replace(/__HERE__/ig, end+1);
	if(totalPage>end+1) html += conf[5].replace(/__HERE__/ig, totalPage);
	
	//alert(html);
	//alert(html.replace(/__URL__/ig, toUrl));

	return html.replace(/__URL__/ig, toUrl);
}

