document.domain = 'v6.com.cn';
//公用库类
var v6Lib = {
	bbsurl: 'http://b1.v6.com.cn/',
	hqurl: 'http://h1.v6.com.cn/',
	infourl: 'http://i2.v6.com.cn/',
	twitterurl: 'http://t1.v6.com.cn/',
	avatarurl: 'http://b1.v6.com.cn/customavatars/avatar.php',
	wikiurl: 'http://w1.v6.com.cn/',
	chatroomurl: 'http://c1.v6.com.cn/',
	v6url: 'http://www.v6.com.cn/',
	webimurl: 'http://w2.v6.com.cn/',
	// initialize
	name: 'v6', version: '1.0',
	showDebug: false, log: [], debugBox: null,
	// browser type
	isIE: Prototype.Browser.IE,
	isFF: Prototype.Browser.Gecko,
	isOP: Prototype.Browser.Opera,
	isSF: Prototype.Browser.WebKit,
	isCM: this.isSF && navigator.userAgent.indexOf('Chrome/') > -1,

  // 生成 debug 调试框
  debug: function(msg) {
		if(!Object.isString(msg) || !this.showDebug){
			return;
		}
		// 如果存在控制台，则直接利用 console 调试
		if(typeof console !='undefined' && console.log){
		   console.log(msg);
		   return;
		}

		// 错误信息缓存
		this.log.push(msg);

	   // 判断是否加载完
	   if(! document.body ){
		   if(!this.log.length){
			   var __thisFn = arguments.callee;
			   document.observe("dom:loaded",  __thisFn.bind(this));
		   }
		   return;
	   }
	   if(this.debugBox){
		   this.debugBox.value = this.log.join('\r\n');
		   this.debugDlg.show();
	   }else{
		   // 创建debug窗
		   this.debugDlg = new Element('div', { 'style' : 'position:absolute;left:0px;top:0px;z-index:100001'});
		   var sbody = '\t<div id="'+this.name+'_debug_box" style="background:#EFF0E6;width:320px;height:245px;border:1px solid '+
			'#6298CD;text-align:center;FILTER: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135,strength=3);">'+
			'<div id="'+this.name+'_debug_bar" style="background:#333366;cursor:pointer;height:23px;width:320px;-moz-user-select:none;" unselectable="true" >'+
			'<div unselectable="true"  style="font-weight:bold;font-size:12px;width:290px;height:23px;text-align:center;color:#fff;padding:3px 2px 0px 5px;float:left;"> --------- v6Lib debug '+this.version+'  --------- </div><div style="clear:right;float:right;"></div></div>'+
			'<div id="'+this.name+'_debug_content" style="width:320px;height:210px;overflow:auto;padding-top:5px;"></div></div>';
		   this.debugDlg.update(sbody);
		   document.body.appendChild(this.debugDlg);

		   // 创建 debug textarea
		   this.debugBox = new Element('textarea', {rows : this.isIE?12:10, cols : 33, value : msg } );
		   $(this.name + '_debug_content').appendChild(this.debugBox);

		   // 关闭链接
		   var Close = new Element('span', { title : 'Close', 'style' : 'cursor:pointer;color:#fff;margin-right:10px;'}).update('x');
		   var debugBar = $(this.name + '_debug_bar');
		   debugBar.appendChild(Close);
		   Close.observe('click', (function(){ this.debugDlg.hide(); }).bind(this));

		   // 修正位置
		   new v6Lib.Dialog().divInit(this.debugDlg,  0, 0);
		   // 实例化拖拽
		   new v6Lib.Drag(this.debugDlg, { 'handle' : debugBar });
	   }
  },
  // 判断源数据是否包含数组里的内容
  inArr: function(sorce, arr) {
		for (var i=0; i<arr.length; i++){
		   if(sorce.toString().indexOf(arr[i])!=-1) return true;
		}
		return false;
  },
  // 判断参数是否为空
  isNull: function(o) {
		return this.isObject(o) && !o;
  },
  // 判断参数是否为对象
  isObject: function(o) {
		return typeof(o) == 'object';
  },
  // 动态加载Script脚本文件
  loadScript: function(src) {
		var scriptTags = document.getElementsByTagName('script');
		var script = null;
		for(var i=0;i<scriptTags.length;i++){
		   if(scriptTags[i].src==src){
			   return scriptTags[i];
		   }
		}
		var head = document.getElementsByTagName('head')[0];
	    script = document.createElement('script');
		script.setAttribute('type', 'text/javascript');
		script.setAttribute('src', src);
		head.appendChild(script);
  },
  // 动态批量导入Script脚本文件
  importScript: function(files) {
		if(!files) return;
		if(!Object.isArray(files)) files = Array(files);
		if(document.getElementsByTagName && document.createElement){
		   for(var i = 0; i < files.length; i++) {
			   this.loadScript(files[i]);
		   }
		}
  },
  // 动态批量导入CSS样式表文件
  importCSS: function(files) {
		if(!files) return;
		if(!this.isArray(files)) files = Array(files);
		if(document.getElementsByTagName && document.createElement){
		   var head = document.getElementsByTagName('head')[0];
		   for(var i = 0; i < files.length; i++) {
			   var link = document.createElement('link');
			   link.setAttribute('type', 'text/css');
			   link.setAttribute('rel', 'stylesheet');
			   link.setAttribute('href', files[i]);
			   head.appendChild(link);
		   }
		}
  },
  getCookie:function(name){
		var search = name + "=";
		var offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			var end = document.cookie.indexOf(";", offset);
			if (end == -1){
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(offset, end));
		}else {
			return "";
		}
	},
	setCookie:function(name,value,hours){
		if(arguments.length>2){
			var expireDate=new Date(new Date().getTime()+hours*3600000);
			document.cookie = name + "=" + escape(value) + "; path=/; domain=v6.com.cn; expires=" + expireDate.toGMTString();
		}else{
			document.cookie = name + "=" + escape(value) + "; path=/; domain=v6.com.cn";
		}
	},
  // 获取URL参数
  getParameter: function(name) {
		var querystring = document.location.search;
		var items = [], item = [];
		var size = 0;
		querystring = querystring.substring(1);
		items = querystring.split("&");
		size = items.length;
		for (var i = 0; i < size; i++){
			item = items[i].split("=");
			if(item.length > 1 && name == item[0]){
				return item[1];
			}
		}
		return '';
  },
  // 将json字符解析成对象
  j2o: function(str) {
	  try{
		  return new Function('return ' + str +';')();
	  }catch(e){
		  return {};
	  }
  },
	formatTime:function(seconds) {
		var timeStr = "";
		seconds = parseInt( seconds, 10 );
		if( isNaN( seconds ) ){
			timeStr = "";
		}else{
			var d = new Date(seconds * 1000);
			var y = d.getFullYear();
			var m = v6Lib.fillZero(d.getMonth() + 1);
			var day = v6Lib.fillZero(d.getDate());
			var hour = v6Lib.fillZero(d.getHours());
			var _min = v6Lib.fillZero(d.getMinutes());
			timeStr = y + "-" + m + "-" + day + "  " + hour + ":" + _min;
		}
		//alert( timeStr );
		return timeStr;
	},
	fillZero:function(d) {
		return parseInt(d) > 9 ? (d + "") : ("0" + d);
	},

	getMsgType:function(t) {
		return 'icon_userthreads';
	},
	//字符截取：中英文等长截断
	countCharacters:function(str,size){
		 var totalCount = 0; 
		 var newStr = "";
		 for (var i=0; i<str.length; i++) { 
			 var c = str.charCodeAt(i); 
			 if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) { 
				 totalCount++; 
			 }else {    
				 totalCount+=2; 
			 } 
			 if(totalCount<size){
				 newStr = str.substring(0,i+1);
			 }else{
				 return newStr+"...";
			 }
		 }
		 return newStr;
	}
};


/********************
 *	服务器通讯类
 *******************/

// js 加载
v6Lib.JSLoader = Class.create();
v6Lib.JSLoader.prototype = {
  initialize: function() {
  },
  get: function(url){
	  var script = new Element('script', { 'src': url||'', type: 'text/javascript'});
	  $$('head')[0].appendChild(script);
	  if(v6Lib.isIE){
			script.observe('readystatechange', function() {
				if( script.readyState == "complete" ){
					$$('head')[0].removeChild(script);
				}
			});
	  }else{
			script.observe('load', function() {
				$$('head')[0].removeChild(script);
			});
	  }
  }
};

// ajax 加载类
v6Lib.Ajax = Class.create();
v6Lib.Ajax.prototype = {
  initialize: function(url, opt) {
	  this.proxy = '/js/proxy.php';
	  this.useProxy = (function(){
		  var tmp = $A(url.match(/(\w+):\/\/([^/:]+)(:\d*)?([^# ]*)/));
		  return !!tmp.length && !(tmp[2] == location.hostname);
	  })();
	  this.opt = Object.extend({ method : 'get', update : false }, opt);
	  if(this.opt.method.toLowerCase() == 'get' || this.useProxy){
		  this.get(url);
	  }else{
		  this.post(url);
	  }
  },
  get: function(url){
	  // ajax proxy url 处理跨域问题
	  if(this.useProxy){
		  url = this.proxy + '?url=' + encodeURIComponent(url);
	  }
	  if(!this.opt.update){
	  	  // 普通get请求
		  new Ajax.Request(url, this.opt);
	  }else if(!this.opt.frequency && !this.opt.decay){
		  // 自动更新指定容器
		  new Ajax.Updater(this.opt, url, this.opt);
	  }else{
		  // 定时更新指定容器
		  new Ajax.PeriodicalUpdater(this.opt.items, url, this.opt);
	  }
  },
  post: function(url){
	  // post 请求
	  new Ajax.Request(url, this.opt);
  }
};

// interface 类
v6Lib.Interface = Class.create({
  initialize: function(url, onSuccess, onError) {
	  this.onSuccess = onSuccess || function(){};
	  this.onError = onError || function(){};
	  new v6Lib.Ajax(url, { 'onSuccess' : this.parseCb.bind(this), 'onFailure' : this.onError.bind(this) });
  },
  // 解析接口返回数据
  parseCb: function(xhr){
	  var req = v6Lib.j2o(xhr.responseText);
	  if(req.status == '1'){
		  try{
			  this.onSuccess(req.data, xhr);
		  }catch(e){ v6Lib.debug('v6Lib.Interface.parseCb - onSuccess: [' + e.description + ']'); }
	  }else{
		  try{
			  this.onError(xhr);
		  }catch(e){ v6Lib.debug('v6Lib.Interface.parseCb - onError: [' + e.description + ']'); }
	  }
  }
});


/********************
 *	模块管理类
 *******************/

v6Lib.Module = Class.create();
v6Lib.Module.prototype = {

	initialize: function() {
		this.ModuleList = {};
		document.observe("dom:loaded", this.init.bind(this));
	},

	// 添加模块
	add: function(name, module){
		if(! (name in this.ModuleList)){
			this.ModuleList[name] =  module;
		}else{
			v6Lib.debug('v6Lib.Module.add - 存在同名模块[' + name + ']');
		}
	},

	// 执行模块列表
	init: function(){
		for( name in this.ModuleList ){
			try{
				this.ModuleList[name]();
			}catch(e){
				v6Lib.debug('v6Lib.Module.init - Module ['+ name +'] - err: ' + e.description);
			}
		}
	}
};
// v6Lib.Module类实例
var vModule = new v6Lib.Module();


/********************
 *	UI、交互控制类
 *******************/

// 层模拟弹出窗口
v6Lib.Dialog = Class.create();
v6Lib.Dialog.prototype = {
	initialize : function () {

	},
	// 初始化层位置
	divInit: function (sId, x, y){
		 if(!$(sId)) return;
		 var target = $(sId);
			 target.style.display = '';
			 target.style.position = 'absolute';

		 //x align
		 switch(x){
			 case 0: //center
				target.style.left = ((document.body.clientWidth / 2) - (target.offsetWidth / 2))+'px';
				break;
			 case 'l': //left
				target.style.left = '0px';
				break;
			 case 'r': //right
				target.style.right = '0px';
				break;
			 default: //use1r define
				target.style.left = x;
				break;
		 }
		 //y align
		 switch(y){
			 case 0: //center
				target.style.top = ((document.body.clientHeight / 2 + document.body.scrollTop) - (target.offsetHeight / 2))+'px';
				break;
			 case 't': //top
				target.style.top = '0px';
				 break;
			 case 'b': //bottom
				target.style.top = (document.body.clientHeight + document.body.scrollTop)+'px';
				 break;
			 default: //user define
				target.style.top= y;
				break;
		 }
	},
	//新建窗口
	open: function (wId, title, content, contenturl, paraObj){
		if(!paraObj) return;

		wId = 'neuPopupWin';

		//背景层，用于遮盖页面
		var divbg = document.createElement('div');
			divbg.id = wId+'_bg';
			divbg.style.width = "100%";
			divbg.style.height = "100%";
			divbg.style.top = '0px';
			divbg.style.left = '0px';
			divbg.style.zIndex = '9999';
			divbg.style.background = '#cccccc';
			divbg.style.position = "absolute";
			divbg.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=65,finishOpacity=100);';

		//窗体层，用于装载窗口内容
		var divWin=document.createElement('div');
			divWin.id=wId;
			divWin.style.zIndex='10000';

		//获取参数
		var w = (paraObj.w)?parseInt(paraObj.w):'';
		var h = (paraObj.h)?parseInt(paraObj.h):'';
		var x = (paraObj.x)?parseInt(paraObj.x):0;
		var y = (paraObj.y)?parseInt(paraObj.y):0;

		if (w=='' || w<100) w=100;
		if (h=='' || h<100) h=100;

		//是否有关闭按钮
		var closeBtnStr = (paraObj.close)?'<img alt="Close" src="images/close.gif" id="popupWinClose" onclick="javascript:nwin.close();" style="cursor: hand;">':'';

		//创建窗口内容
		var sbody='\t<div id="'+wId+'_box" style="background-color:#EFF0E6;width:'+w+'px;height:'+h+'px;border:1px solid '+
			'#6298CD;text-align:center;FILTER: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135,strength=3);">'+
			'<div id="'+wId+'_bar" style="background-image:url(images/barn.png);background-repeat:repeat-x;height:23px;'+
			'width:'+w+'px;-moz-user-select:none;" onMouseDown="javascript:new v6Lib.jDrag().moveStart(event,\''+wId+'\');">'+
			'<div style="clear:left;float:left;font-weight:bold;text-align:left;color:#FFFFFF;padding:2px 2px 0px 5px;">'+ title +
			'</div><div id="popupClose" style="clear:right;float:right;">'+closeBtnStr+	'</div></div>'+ '<div id="'+wId+
			'_c" style="width:'+w+'px;height:'+(h-25)+'px;overflow-x:auto;overflow-y:auto;">'+content+'</div></div>';

			divWin.innerHTML = sbody;

			document.body.appendChild(divWin);
			document.body.appendChild(divbg);

			//通过ajax更新窗口内容
			if(contenturl){
				var getAjaxContent= new neuAjax();
				getAjaxContent.getRequest(contenturl,function(o){ Element.update(wId+'_c',o.responseText); });
			}

			//初始化层位置
			this.divInit(wId, x, y);

			//隐藏 select 等特殊对象
		    oHideElement.hideAll($(divbg));
	},
	// 关闭窗口
	close : function (){
		try{
			    var wId = 'neuPopupWin';
				document.body.removeChild($(wId+'_bg'));
				document.body.removeChild($(wId));

			    //显示隐藏的特殊对象
		        oHideElement.show();
		}catch(e){ }
	},
	// 更新窗口
	update : function (wId, content, canClose){
		try{
			var wId = 'neuPopupWin';
			if(!$(wId)) return;

			Element.update(wId+'_c', content);

			//能否关闭
			if(canClose){
				$('popupClose').innerHTML ='<img alt="Close" src="images/close.gif" id="popupWinClose" onclick="javascript:nwin.close(this);" style="cursor: hand;">';
			}else{
				$('popupClose').innerHTML = '';
			}

		} catch(e){}
	}
};

// 拖拽类
v6Lib.Drag = Class.create();
v6Lib.Drag.prototype = {
	initialize : function (dragObj, opt) {
		if(!$(dragObj)){
			v6Lib.debug('v6Lib.Drag - 拖动容器[' + dragObj + ']不存在!');
		}
		// 参数配置
		this.opt = Object.extend({
					'handle' : '' ,
					limit : false,
					range :  [0, document.body.clientWidth || 0, document.body.clientHeight || 0, 0]  // top, right, bottom, left
				}, opt);
		this.dragObj = $(dragObj);
		this._handle = $(this.opt.handle) || this.dragObj;
		this._handle.observe('mousedown', this.dragStart.bind(this));

		this.dragObj.absolutize(); // 绝对定位
	},
	dragStart : function (event) {
		// 初始座标及偏移量
		var pos = this.dragObj.cumulativeOffset();
		this._oldX = Event.pointerX(event) - pos.left;
		this._oldY = Event.pointerY(event) - pos.top;

		// 修正限制区域
		if(this.opt.limit){
			this.fixRange();
		}
		// 事件句柄
		this.moveHandle = this.moving.bindAsEventListener(this);
		this.upHandle = this.dragEnd.bind(this);
		// 事件绑定
		document.observe('mousemove', this.moveHandle);
		document.observe('mouseup', this.upHandle);

		// fix event
		if(v6Lib.isIE){
			// 捕获鼠标动作
			this.dragObj.setCapture();
			// 判断焦点丢失
			this.dragObj.observe('losecapture', this.upHandle);
		}else{
			// (ff下通过window.blur判断焦点丢失)
			window.observe('blur', this.upHandle);
		}
		// 取消系统的默认动作
		Event.stop(event);
	},
	dragEnd : function (event) {
		// 取消事件绑定
		document.stopObserving('mousemove', this.moveHandle);
		document.stopObserving('mouseup', this.upHandle);

		if(v6Lib.isIE){
			// 释放鼠标捕获
			this.dragObj.releaseCapture();
			this.dragObj.stopObserving('losecapture', this.upHandle);
		}else{
			window.stopObserving('blur', this.upHandle);
		}
	},
	fixRange : function () {
		// 修正最小范围
		var range = this.opt.range;
		var mRight = Math.max(range[1], range[3] + this.dragObj.getWidth());
		var mBottom = Math.max(range[2], range[0] + this.dragObj.getHeight());
		range = [range[0], mRight, mBottom, range[3]];
	},
	moving : function (event) {
		// 清除选择(防止拖动过程中选择文本)
		window.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
		// 计算新位置
		var nLeft = Event.pointerX(event) - this._oldX;
		var nTop =  Event.pointerY(event) - this._oldY;
		// 范围限制
		if(this.opt.limit){
			var range = this.opt.range;
			//v6Lib.debug('range: ' + range[0] + '||' + range[1] + '||' + range[2] + '||' + range[3]);
			nLeft = Math.max(Math.min(nLeft, range[1] - this.dragObj.getWidth()), range[3]);
			nTop = Math.max(Math.min(nTop, range[2] - this.dragObj.getHeight()), range[0]);
		}
		// 设置座标
		if(!this.opt.lockX){ this.dragObj.setStyle( {'left' : nLeft + 'px'} ); }
		if(!this.opt.lockY){ this.dragObj.setStyle( {'top' : nTop + 'px'} ); }
	}
}

// tab 管理类
v6Lib.Tab = Class.create({
	initialize: function(contentBox, opt){
		this.tabList = {};
		this.contentBox = $(contentBox);
		if(!this.contentBox){
			v6Lib.debug('feed-> tab -> initialize - contentBox 容器不存在!');
		}
		this.opt = Object.extend({'tabOnClass' : 'on_this', 'curTab' : null}, opt||{});
	},
	// 添加tab
	addTab: function(tabId, contentCb){
		var curTab = $(tabId);
		if(curTab){
			curTab.observe('click', this.showTab.bind(this));
			this.tabList[tabId] = contentCb;
			if(!this.opt.curTab){
				this.opt.curTab = curTab;
			}
			// fix style
			if(v6Lib.isIE){
				curTab.writeAttribute('hideFocus','true');
			}else{
				curTab.setStyle({'outline':'none'});
			}
		}
	},
	// 显示tab
	showTab: function(event){
		var el = Event.element(event);
		if('A' == el.tagName &&  this.opt.curTab != el){
			if(this.opt.curTab){
				this.opt.curTab.removeClassName(this.opt.tabOnClass);
			}
			el.addClassName(this.opt.tabOnClass);
			// 更新 content
			if(el.id in this.tabList){
				var content = this.tabList[el.id];
				if(Object.isString(content)){
					this.contentBox.update(content);
				}else if(Object.isFunction(content)){
					try{
						var result = content({ content: this.contentBox, link: el, instance: this });
						if(Object.isString(result)){
							this.contentBox.update(result);
						}
					}catch(e){
						v6Lib.debug('feed-> tab -> showTab - ' + e.description);
					}
				}
			}
			// 当前tab对象
			this.opt.curTab = el;
		}
	}

});

// 分页显示类
v6Lib.Pagination = Class.create({
	// 初始化
	initialize: function(opt){

		// 默认分页配置
		this.config = Object.extend({
			"container"		: null,			// 父容器
			"total"			: 1,			// 数据总条数
			"pageSize"		: 10,			// 每页显示的数据条数 (默认10条)
			"curPage"		: 1,			// 当前页码 (默认为第1页)
			"startPage"		: 1,			// 开始页 (默认为第1页)
			"pageCount"		: 1,			// 总页数 (默认为1页，自动根据total 和 pageSize 计算)

			 // 分页布局模板
			"layoutTpl"		: '<ul class="xs-pagination">\
							     <li class="info">Total #{pagCount} : </li>\
							     #{prev}\
								 #{pageNum}\
								 #{next}\
							   </ul>',

			"linksTpl"		: '<li class="#{class}" #{title} >#{link}</li>',	// 分页链接模板

			"prev"			: { txt : '? Previous' , normal : 'previous', disabled : 'previous-off', title : 'title="Previous page"' }, // 上一页配置

			"next"			: { txt : 'Next ?', normal : 'next', disabled : 'next-off' , title : 'title="Next page"'},  // 下一页配置

			"pageActive"	: 'active',			// 当前页码激活状态样式

			"pageLink"		: '?page=#{page}'	// 默认分页链接url规则 #{page} 替换为当前页码
			}, opt || {});

		this._parent = $(opt.container);
		if(! this._parent ) {
			v6Lib.debug('v6Lib.Pagination -- 父容器[' + opt.container + ']不存在');
			return;
		}
		//this.show();
	},
	/**
	 * 根据参数计算分页所需数据
	 */
	calc : function (nCurPage, nTotal) {

		var opt = this.config;

		// 总数
		nTotal && (opt.total = nTotal * 1);
		// 当前页
		nCurPage && (opt.curPage = nCurPage * 1);

		// 起始页
		opt.startPage = opt.startPage * 1;

		// 计算总页数
		opt.pageCount = opt.total / opt.pageSize || opt.pageCount * 1;
		opt.pageCount = opt.pageCount % opt.pageSize != 0 ? Math.round(opt.pageCount + 0.5) : opt.pageCount;

		// 当前页不能超过总页数
		opt.curPage = (opt.curPage > opt.pageCount) ? opt.startPage : opt.curPage * 1;

		// 上一页
		opt.prevPage = (opt.curPage - 1) || 1;

		// 下一页
		opt.nextPage = (opt.curPage + 1) > opt.pageCount ? opt.pageCount : (opt.curPage + 1);
	},
	/**
	 * 根据参数及模板生成分页html
	 */
	parseHTML : function () {

		var opt = this.config;
		var getPage = function(type, page){ return Object.isFunction(opt.pageLink) ? '#' + type  : opt.pageLink.replace(/#{page}/ig, page); }
		// 页码
		var _pageNum = [];
		for(var i = 1; i<=opt.pageCount; i++){
			var oPageNum = {
					'link'  : (i != opt.curPage ? '<a href="' + getPage('page', i) +'">' + i +'</a>' : i),
					'class' : (i == opt.curPage ? opt.pageActive : '')
				};
			_pageNum.push( new Template(opt.linksTpl).evaluate( oPageNum ) );
		}
		// 上页
		var oPrevPage = {
				'link'	: (opt.curPage != opt.startPage ? '<a href="' + getPage('prev', opt.curPage - 1) +'">' + opt.prev.txt +'</a>' : (opt.prev.disabled ? opt.prev.txt : '') ) ,
				'class'	: (opt.prev.disabled ? (opt.curPage != opt.startPage ? opt.prev.normal : opt.prev.disabled) : ''),
				'title' : opt.prev.title ? opt.prev.title : ''
			};
		var _prevPage = new Template(opt.linksTpl).evaluate( oPrevPage );

		// 下页
		var oNextPage = {
				'link'	: (opt.curPage != opt.pageCount ? '<a href="' + getPage('next', opt.curPage + 1) +'">' + opt.next.txt +'</a>' : (opt.next.disabled ? opt.next.txt : '') ) ,
				'class'	: (opt.next.disabled ? (opt.curPage != opt.pageCount ? opt.next.normal : opt.next.disabled) : ''),
				'title' : opt.next.title ? opt.next.title : ''
			};
		var _nextPage = new Template(opt.linksTpl).evaluate( oNextPage );

		// 模板替换
		var t = new Template(opt.layoutTpl);
		var o = {
			pagCount : opt.pageCount,
			prev	 : _prevPage,
			next	 : _nextPage,
			pageNum	 : _pageNum.join('')
		};
		this._parent.update( t.evaluate( o ) );

		// 修正链接参数/绑定事件
		if(Object.isFunction(opt.pageLink)){
			this.fixLinks();
		}
	},
	/**
	 * 修正分页链接事件 (主要针对ajax调用)
	 */
	fixLinks : function () {
		var opt = this.config;
		var _area = this._parent;
		var _select = function(type){
				// 修正ie下链接
				var sIeHref = (v6Lib.isIE ? location.href.replace(/#\w+/ig, '') : '');
				return $(_area).select( 'a:[href=' + sIeHref + '#'+type+']' );
			};
		var _goPage = function(page){ try{ opt.pageLink(page); } catch(e){ v6Lib.debug('v6Lib.Pagination - config.pageLink :' + e.description); } };
		var _prev = _select('prev')[0];  // 上页
		var _next = _select('next')[0];	 // 下页
		var _pages = _select('page');	 // 页码

		_prev && ( _prev.observe('click', _goPage.bind(this, opt.curPage - 1)) );
		_next && ( _next.observe('click', _goPage.bind(this, opt.curPage + 1)) );

		for(var i = 0, l = _pages.length; i < l; i++){
			var _cur = _pages[i];
			var _num = _cur.innerHTML;
			_cur.observe('click', _goPage.bind(this, _num));
			// fix hash
			_cur.href = '#page' + _num;
		}
		// fix hash
		if(_prev){ _prev.href = '#page' + (opt.curPage - 1); }
		if(_next){ _next.href = '#page' + (opt.curPage + 1); }
	},
	/**
	 * 根据参数显示分页
	 */
	show : function (nCurPage, nTotal) {
		// 计算
		this.calc(nCurPage, nTotal);
		// 显示
		this.parseHTML();
	}
});



//处理脚本出错
//window.onerror = function(sMsg, sUrl, sLine){
//	if(v6Lib.showDebug){
//		v6Lib.debug("脚本出错:\n描  述 - "+sMsg+"\n错误行 - "+sLine+" 行\n错误源 - "+sUrl);
//		return true;
//	}else{
//		return false;
//	}
//};

function debugFun(msg){
	if( Object.isString(msg) ){
		v6Lib.debug(msg);
	}
}