var PAGING = function(obj) {
	this.classObj = obj;
	this.first = 1;
	this.prev = 1;
	this.next = 1;
	this.last = 1;
	this.page = 1;
	this.totRows = eval(this.classObj+".totRows");
	this.config = {
		cols : eval(this.classObj+".cols"),
		rows : eval(this.classObj+".rows"),
		style : "cursor:pointer",
		space : " <span style='color:#EEEADB'>l</span> ",
		prevIcon : "<img src='http://"+document.domain+"/images/board_prev.gif' border='0' align='absmiddle'>",
		nextIcon : "<img src='http://"+document.domain+"/images/board_next.gif' border='0' align='absmiddle'>"
	};
}
//## ÆäÀÌÂ¡ °è»ê
PAGING.prototype.calculate = function() {
	var last = Math.ceil(this.totRows / this.config.rows);	// ³¡ ÆäÀÌÁö
	var curpos = Math.ceil(this.page / this.config.cols);	// Çö ÆäÀÌÁö
	var st_page = (curpos-1) * this.config.cols + 1;		// Çö ½ÃÀÛ ÆäÀÌÁö
	var en_page = (curpos * this.config.cols >= last) ? last : curpos * this.config.cols + 1;	// Çö ³¡ ÆäÀÌÁö

	this.prev = (st_page==1) ? 0 : st_page-1;
	this.next = (en_page==last) ? last : en_page;
	this.last = last;
}
//## ÆäÀÌÂ¡ Ãâ·Â 
PAGING.prototype.formalize = function(page) {
	this.page = page;
	this.calculate();

	if(this.prev==-1) return '';
	var _pages = new Array();
	var _PAGE = new Array(3);

	var rows = 0;
	for(var i=this.prev; i<=this.next; i++) {
		var no = i;
		if(i==0) continue;
		if(i==this.page) _pages[rows++] = "<span style='font-weight:bold;color:#FF6600'>"+no+"</span>";
		else {
			if(i!=this.first && i==this.prev) _PAGE[0] = "<span style='"+this.config.style+"' onClick='"+this.classObj+".getPage("+i+")'>"+this.config.prevIcon+"</span>";
			else if(i!=this.last && i==this.next || i>this.prev+this.config.cols) _PAGE[2] = "<span style='"+this.config.style+"' onClick='"+this.classObj+".getPage("+i+")'>"+this.config.nextIcon+"</span>";
			else _pages[rows++] = "<span style='"+this.config.style+"' onClick='"+this.classObj+".getPage("+i+")'>"+no+"</span>";
		}
	}
	_PAGE[1] = _pages.join(this.config.space);
	if(_PAGE[2]==null) _PAGE.pop();
	if(_PAGE[0]==null) _PAGE.shift();
	return (_PAGE.length>1) ? _PAGE.join(" &nbsp; ") : _PAGE;
}

//##################################################################################
//## ÆäÀÌÂ¡ È÷½ºÅä¸® ÇÚµé·¯ :: Áß¿ä
var handleHistoryChange = function(newLocation, historyData) {

	if(newLocation=="") newLocation = "section:null";
	newLocation = newLocation.replace(/section\:/, "");
	if(newLocation=="null") window.history.back();

	if(newLocation.indexOf("msg")!=-1) msg.getPage(historyData); // ¸Þ½ÃÁö
	if(newLocation.indexOf("regist")!=-1) regist.getPage(historyData); // µî·Ï¹°°Ç
	if(newLocation.indexOf("payment")!=-1) payment.getPage(historyData); // °áÁ¦
	if(newLocation.indexOf("member")!=-1) member.getPage(historyData); // È¸¿ø
	if(newLocation.indexOf("goods")!=-1) goods.getPage(historyData); // ÀüÃ¼¹°°Ç
	if(newLocation.indexOf("rooms")!=-1) rooms.getPage(historyData); // ¹°°Ç
	if(newLocation.indexOf("send")!=-1) { // º¸³½¸Þ½ÃÁö
		msg.curQue = "send";
		msg.getPage(historyData);
	}
	if(newLocation.indexOf("receive")!=-1) { // ¹ÞÀº¸Þ½ÃÁö
		msg.curQue = "receive";
		msg.getPage(historyData);
	}
	if(newLocation.indexOf("scrap")!=-1) scrap.getPage(historyData); // ½ºÅ©·¦
	if(newLocation.indexOf("settle")!=-1) settle.getPage(historyData); // °áÁ¦³»¿ª

}
//## ÆäÀÌÂ¡ È÷½ºÅä¸® ÇÚµé·¯ µî·Ï
Event.observe(window, "load", function() {
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(handleHistoryChange);
});
