function pageNav(){
	this.processParams = "";// must
	this.processFile = "";// must
	this.page = 1;// must
	this.commentTotal = 1;// must
	this.commentsId = "";
	this.comments = null;//MUST
	this.loader = null;
	this.currentPage =1;
	this.pageName = "page";
	this.useCache = false;
	this.commentPaging = 50;//pageSize
	this.commentPages = 1;//pages
	this.commentNavId = "";
	this.commentNav = null;//id of the bar showned, MUST
	this.navigation = "";// navigation content
	this.instanceName = "";//MUST
	this.ajaxResponseText = "";
	this.breakNavigion = false;
	
	this.show = function (page){
		
		this.commentNav = document.getElementById(this.commentNavId);
		this.comments = document.getElementById(this.commentsId);
		if(this.loaderId!=""){
			this.loader = document.getElementById(this.loaderId);
			this.loader.style.display="";
		}
		this.processParams = this.processParams.replace(/\"/g,'%22'); // urlencode "
		if (page > this.currentPage) this.useCache = true;
		else this.useCache = false;
		//this.useCache = false;
		if (page == 'next') ++this.currentPage;
		else if (page == 'prev') --this.currentPage;
		else this.currentPage = page;
		if (this.currentPage < 1)
		this.currentPage = 1;
		var __ajax_responseText="";
		var paras =this.setParam(this.pageName, this.currentPage);
		var opt = {
			// Use POST
			method: 'get',
			// Send this lovely data
			postBody: '',
			// Handle successful response
			onSuccess: function (t){},
			// Handle 404
			on404: function(t) {
				alert('Error 404: location "' + t.statusText + '" was not found.');
			},
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
		try{
			eval("opt.onSuccess = "+this.commentsId+"_ajaxShow");
		}
		catch(E){
			alert(E.message);
		}
		try{
			new Ajax.Request(this.processFile+"?"+paras, opt);
		}
		catch(e){alert(e.message)};
		// Find total pages
		//var commentPages = 1;
		if ((this.commentTotal % this.commentPaging) > 0) this.commentPages = parseInt(this.commentTotal / this.commentPaging) +1;
		else this.commentPages = this.commentTotal / this.commentPaging;
		if(this.commentPages<=1) this.commentNav.innerHTML = "";

		this.navigation = '<div style="width:250px; display: inline; text-align:right;">';
		this.navigation += '(' + this.currentPage + ' of ' + this.commentPages + ') ';

		if (this.commentPages > 1) {
			// Show fast history jump
			if ((this.currentPage - 10) > 0) this.navigation += '<a class="pagenav"  href="javascript:'+this.instanceName+'.show(' + (this.currentPage -10) + ')">' + (this.currentPage -10) + '</a> ... ';
			// Show 10 jumps back and forth
			for (var nr=this.currentPage-4; nr < (this.currentPage+4); nr++) {
				if (nr < 1) continue;
				if (nr > this.commentPages) break;
				var style = '';
				if (nr == this.currentPage) style = 'color: orange';
				this.navigation += '<a class="pagenav" style="' + style + '" href="javascript:'+this.instanceName+'.show(' + nr + ')">' + nr + '</a> ';
			}
			// Show fast future jump
			if ((this.currentPage + 10) <= this.commentPages) this.navigation += '... <a class="pagenav" href="javascript:'+this.instanceName+'.show(' + (this.currentPage +10) + ')">' + (this.currentPage +10) + '</a>';
			if(this.breakNavigion==true){
				this.navigation += '</div><BR/><div style="display: blod; text-align:left;float:left;clear:both">';
			}
			else{
				//break prev | next
				this.navigation += '</div><div style="display: inline; text-align:right;">&nbsp;&nbsp;&nbsp;&nbsp;';
			}
			// Show prev/next buttons
			if (this.currentPage > 1) this.navigation += '<a class="pagenav" href="javascript:'+this.instanceName+'.show(\'prev\')">Prev</a> ';
			else this.navigation += '<span style="color:#575757">Prev</span> ';
			if (this.currentPage < this.commentPages) this.navigation += ' | <a class="pagenav" href="javascript:'+this.instanceName+'.show(\'next\')">Next</a>&nbsp;';
			else this.navigation += ' | <span style="color:#575757">Next </span>&nbsp;';
			this.navigation += '</div>';
			this.commentNav.innerHTML = this.navigation;
			
		}
		else{
			this.navigation = "";
			this.commentNav.innerHTML = "";
		}
	}
	
	//return navigation content
	this.getNavigation = function(){
		return this.navigation;
	}
	
	
	//set a param with new value
	this.setParam = function(key, newValue){
		if(this.processParams=="")return false;
		var newURL = "";
		var arr = new Array();
		var foundKey = false;
		if(this.processParams.length>0)
		{
			var s = this.processParams.split("&");
			var l = s.length;
			if(l){
				for(var i=0;i<l;i++)
				{
					try{
						var sp=s[i].split("=");
						if(sp[0] == key){
							arr.push(key + "=" + newValue);
							foundKey = true;
						}
						else{
							arr.push(s[i]);
						}
					}
					catch(E){
						//alert(E.message);
					}
				}
				if(!foundKey){
					arr.push(key + "=" + newValue);
				}
			}


		}
		if(arr){
			this.processParams = arr.join("&");
			return this.processParams;
		}
		else return false;
	}
}
