function pageNav(instanceName,url,data,containerId,paggingId,currentPage,commentTotal,pageSize,callBack){
	this.processParams = data;// must
	this.processFile = url;// must
	this.page = currentPage;// must
	this.commentTotal = commentTotal;// must
	this.commentsId = containerId;
	this.comments = null;//MUST
	this.loader = "";
	this.currentPage =1;
	this.pageName = "page";
	this.useCache = false;
	this.commentPaging = !pageSize?50:pageSize;//pageSize
	this.commentPages = 1;//pages
	this.commentNavId = paggingId;
	this.commentNav = null;//id of the bar showned, MUST
	this.navigation = "";// navigation content
	this.instanceName = instanceName;//MUST
	this.ajaxResponseText = "";
	this.breakNavigion = false;
	this.callBack = callBack;
	this.showButtonNum = 3;
	this.ajax = true;
	this.pageSize = pageSize;
	
	if(typeof(pageNav.arguments[9])!='undefined'){
		if(typeof(pageNav.arguments[9].ajax)!='undefined'){
			this.ajax = pageNav.arguments[9].ajax;
		}
	}
	
	this.updatePaging = function(page){
		var showButtonNum;
		
		this.commentNav = document.getElementById(this.commentNavId);
		this.comments = document.getElementById(this.commentsId);
		if(this.loaderId!=""){
			//try{
			//this.loader = document.getElementById(this.loaderId);
			$('#'+this.loaderId).css('display',"");
			//}
			//catch(e){}
		}
		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;
		
		if(this.currentPage <2)showButtonNum = this.showButtonNum*2;
		else showButtonNum = this.showButtonNum;
		
		// 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 = "";
		
		recStart = (this.currentPage-1)*this.pageSize+1;
		recLast = (this.currentPage)*this.pageSize;
		if(recLast>this.commentTotal){
			recLast = this.commentTotal;
		}
		
		this.navigation = '<div style="float:left"><div class="pagesum">'+recStart+'-'+recLast+' of '+this.commentTotal+':</div>';
		//this.navigation += '(' + this.currentPage + ' of ' + this.commentPages + ') ';

		if (this.commentPages > 1) {
			// Show fast history jump
			if ((this.currentPage - showButtonNum) > 1) {
				if(this.ajax){
					this.navigation += '<a href="javascript:'+this.instanceName+'.show(1)"><span>1</span></a>';
				}
				else{
					this.navigation += '<a href="javascript:'+this.instanceName+'.goto(1)"><span>1</span></a>';
				}
			}
			if ((this.currentPage - showButtonNum) > 2) this.navigation += '<div class="pagesum">...</div>';
			// Show 10 jumps back and forth

			for (var nr=this.currentPage-showButtonNum; nr < (this.currentPage+showButtonNum); nr++) {
				if (nr < 1) continue;
				if (nr > this.commentPages) break;
				var style = '';
				if (nr == this.currentPage){
					this.navigation += '<span class="selected">' + nr + '</span> ';
				}
				else{
					if(this.ajax){
						this.navigation += '<a href="javascript:window.'+this.instanceName+'.show(' + nr + ')"><span>' + nr + '</span></a> ';
					}
					else{
						this.navigation += '<a href="javascript:window.'+this.instanceName+'.goto(' + nr + ')"><span>' + nr + '</span></a> ';
					}
				}
			}
			// Show fast future jump
			//if ((this.currentPage + 10) <= this.commentPages) this.navigation += '<div class="pagesum">...</div><a class="pagenav" href="javascript:'+this.instanceName+'.show(' + (this.currentPage +10) + ')"><span>' + (this.currentPage +10) + '</span></a>';
			if(this.breakNavigion==true){
				this.navigation += '<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;';
			}
			
			if (this.currentPage+showButtonNum<this.commentPages){
				if(this.ajax){
					this.navigation += '<div class="pagesum">...</div><a href="javascript:window.'+this.instanceName+'.show(' + this.commentPages + ')"><span>' + this.commentPages + '</span></a> ';
				}
				else{
						this.navigation += '<div class="pagesum">...</div><a href="javascript:window.'+this.instanceName+'.goto(' + this.commentPages + ')"><span>' + this.commentPages + '</span></a> ';
				}
			}
			this.navigation += '</div>';
			
			// Show prev/next buttons
			this.navigation += '<div style="float:right">';
			if (this.currentPage > 1){
				if(this.ajax){
					this.navigation += '<a href="javascript:window.'+this.instanceName+'.show(\'prev\')"><span>Prev</span></a>';
				}
				else{
					this.navigation += '<a href="javascript:window.'+this.instanceName+'.goto(\'prev\')"><span>Prev</span></a>';
				}
			}
			else this.navigation += '<span class="selected">Prev</span> ';
			if (this.currentPage < this.commentPages){
				if(this.ajax){
					this.navigation += '<a class="pagenav" href="javascript:window.'+this.instanceName+'.show(\'next\')"><span>Next</span></a>';
				}
				else{
					this.navigation += '<a class="pagenav" href="javascript:window.'+this.instanceName+'.goto(\'next\')"><span>Next</span></a>';
				}
			}
			else this.navigation += '<span class="selected">Next </span>';
			this.navigation += '</div>';
			
			this.commentNav.innerHTML = this.navigation;
			
		}
		else{
			this.navigation = "";
			this.commentNav.innerHTML = "";
		}
	}
	
	this.show = function (page){
		var showButtonNum;
		
		this.commentNav = document.getElementById(this.commentNavId);
		this.comments = document.getElementById(this.commentsId);
		if(this.loaderId!=""){
			//try{
			//this.loader = document.getElementById(this.loaderId);
			$('#'+this.loaderId).css('display',"");
			//}
			//catch(e){}
		}
		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;
		
		if(this.currentPage <2)showButtonNum = this.showButtonNum*2;
		else showButtonNum = this.showButtonNum;
		
		if(this.ajax){
			var __ajax_responseText="";
	
			if(!this.callBack){
				this.callBack = this.defaultCallBack;
			}
			this.processParams = this.setParam('page_size',this.pageSize);
			var opt = {
					   type: "GET",
					   url: this.processFile,
					   data: this.setParam(this.pageName, this.currentPage),
					   dataType:'text',
					   success:this.callBack
					 };
			try{
				 $.ajax(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 = "";
		
		recStart = (this.currentPage-1)*this.pageSize+1;
		recLast = (this.currentPage)*this.pageSize;
		if(recLast>this.commentTotal){
			recLast = this.commentTotal;
		}
		
		this.navigation = '<div style="float:left"><div class="pagesum">'+recStart+'-'+recLast+' of '+this.commentTotal+':</div>';
		//this.navigation += '(' + this.currentPage + ' of ' + this.commentPages + ') ';

		if (this.commentPages > 1) {
			// Show fast history jump
			if ((this.currentPage - showButtonNum) > 1) {
				if(this.ajax){
					this.navigation += '<a href="javascript:'+this.instanceName+'.show(1)"><span>1</span></a>';
				}
				else{
					this.navigation += '<a href="javascript:'+this.instanceName+'.goto(1)"><span>1</span></a>';
				}
			}
			if ((this.currentPage - showButtonNum) > 2) this.navigation += '<div class="pagesum">...</div>';
			// Show 10 jumps back and forth

			for (var nr=this.currentPage-showButtonNum; nr < (this.currentPage+showButtonNum); nr++) {
				if (nr < 1) continue;
				if (nr > this.commentPages) break;
				var style = '';
				if (nr == this.currentPage){
					this.navigation += '<span class="selected">' + nr + '</span> ';
				}
				else{
					if(this.ajax){
						this.navigation += '<a href="javascript:window.'+this.instanceName+'.show(' + nr + ')"><span>' + nr + '</span></a> ';
					}
					else{
						this.navigation += '<a href="javascript:window.'+this.instanceName+'.goto(' + nr + ')"><span>' + nr + '</span></a> ';
					}
				}
			}
			// Show fast future jump
			//if ((this.currentPage + 10) <= this.commentPages) this.navigation += '<div class="pagesum">...</div><a class="pagenav" href="javascript:'+this.instanceName+'.show(' + (this.currentPage +10) + ')"><span>' + (this.currentPage +10) + '</span></a>';
			if(this.breakNavigion==true){
				this.navigation += '<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;';
			}
			
			if (this.currentPage+showButtonNum<this.commentPages){
				if(this.ajax){
					this.navigation += '<div class="pagesum">...</div><a href="javascript:window.'+this.instanceName+'.show(' + this.commentPages + ')"><span>' + this.commentPages + '</span></a> ';
				}
				else{
						this.navigation += '<div class="pagesum">...</div><a href="javascript:window.'+this.instanceName+'.goto(' + this.commentPages + ')"><span>' + this.commentPages + '</span></a> ';
				}
			}
			this.navigation += '</div>';
			
			// Show prev/next buttons
			this.navigation += '<div style="float:right">';
			if (this.currentPage > 1){
				if(this.ajax){
					this.navigation += '<a href="javascript:window.'+this.instanceName+'.show(\'prev\')"><span>Prev</span></a>';
				}
				else{
					this.navigation += '<a href="javascript:window.'+this.instanceName+'.goto(\'prev\')"><span>Prev</span></a>';
				}
			}
			else this.navigation += '<span class="selected">Prev</span> ';
			if (this.currentPage < this.commentPages){
				if(this.ajax){
					this.navigation += '<a class="pagenav" href="javascript:window.'+this.instanceName+'.show(\'next\')"><span>Next</span></a>';
				}
				else{
					this.navigation += '<a class="pagenav" href="javascript:window.'+this.instanceName+'.goto(\'next\')"><span>Next</span></a>';
				}
			}
			else this.navigation += '<span class="selected">Next </span>';
			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 "page="+newValue;
		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 "page="+newValue;
	}
	this.setCallBack = function (cb){
		this.callBack = cb;
	}
	
	this.defaultCallBack = function(data){
		//document.getElementById(this.commentsId).innerHTML =  data;
	}
	
	this.goto = function(page){
		if (page == 'next') ++this.currentPage;
		else if (page == 'prev') --this.currentPage;
		else this.currentPage = page;
		if (this.currentPage < 1)
		this.currentPage = 1;
		
		if(this.currentPage <2)showButtonNum = this.showButtonNum*2;
		else showButtonNum = this.showButtonNum;
		
		document.location.href = this.processFile+'?'+this.setParam(this.pageName, this.currentPage);
	}
	
	//auto show
	this.show(this.page);
}

