function ajaxPages(){
	this.init = function(){
		this.currentPage=0;
		this.ctrls = new Array();
		if(typeof this.config != 'undefined'){
			var cfg = this.config;
			this.ctrlContainer = (typeof cfg.ctrlContainer == 'string')?
									document.getElementById(cfg.ctrlContainer):
									 (typeof cfg.ctrlContainer == 'object')?cfg.ctrlContainer:document.createElement('DIV');
			this.ctrlContainer.innerHTML = '';
			this.buildOwnCtrls = (typeof cfg.ctrlContainer == 'undefined')?true:false;

			this.pageItems = cfg.pageItems;
			this.totalItems = cfg.totalItems;
			this.pages = new Array();
			for(var i=0; i<parseInt(Math.ceil(this.totalItems/this.pageItems)); i++){
				this.pages.push(i*this.pageItems)
			}
			this.ajax = new Object();
			this.ajax.url = cfg.url;
			this.ajax.node = (typeof cfg.ajaxContainer == 'string')?
									document.getElementById(cfg.ajaxContainer):cfg.ajaxContainer;
			this.container = (typeof cfg.container == 'string')?
									document.getElementById(cfg.container):cfg.container;
			this.ajax.requestVarNames = cfg.requestVarNames;
			this.buildCtrls();
		}
	}
	this.buildCtrls = function(){
		thisObj = this;
		var pv = document.createElement('A');
		pv.href = 'javascript:void(0)';
		pv.innerHTML = '&laquo; Prev';
		pv.onclick = function(){ thisObj.prev(); }
		this.ctrlContainer.appendChild(pv);
		for(var i in this.pages){
			var ctrlunit = document.createElement('A');
			ctrlunit.href = 'javascript:void(0)';
			ctrlunit.innerHTML = '&nbsp;  '+(parseInt(i)+1)+'&nbsp;  ';
			ctrlunit.pos = this.pages[i];
			ctrlunit.index = i;
			ctrlunit.onclick = function(){ thisObj.request(this.pos,this.index,thisObj.pageItems); }
			this.ctrlContainer.appendChild(ctrlunit);
			if(i!=this.pages.length-1){
				var x = document.createTextNode('|');
				this.ctrlContainer.appendChild(x);
			}
			this.ctrls.push(ctrlunit);			
		}	
		var nx = document.createElement('A');
		nx.href = 'javascript:void(0)';
		nx.innerHTML = 'Next &raquo;';
		nx.onclick = function(){ thisObj.next(); }
		this.ctrlContainer.appendChild(nx);

		if(this.buildOwnCtrls)	this.container.appendChild(this.ctrlContainer)	
		this.setCtrls();	
	}
	
	this.prev = function(){
		if(this.currentPage==0)
			return false;
		else
			this.request(this.pages[parseInt(this.currentPage)-1],parseInt(this.currentPage)-1,this.pageItems)
	}
	
	this.next = function(){
		if(this.currentPage==parseInt(this.pages.length)-1)
			return false;
		else
			this.request(this.pages[parseInt(this.currentPage)+1],parseInt(this.currentPage)+1,this.pageItems)
	}

	this.setCtrls = function(){
		for(var i in this.ctrls)
			this.ctrls[i].style.fontWeight = 'normal';
		this.ctrls[this.currentPage].style.fontWeight = 'bold';
		
	}
	
	this.request = function(p,idx,pitms){
		if(this.currentPage==idx) return false;
		this.currentPage = idx;
		this.setCtrls();
		var ajax_req = this.ajax.requestVarNames[0]+'='+p+'&'+this.ajax.requestVarNames[1]+'='+pitms;
		ajax.node = this.ajax.node;
		ajax.post_vars = ajax_req;
		ajax.url = this.ajax.url;
		ajax.makeRequest();
	}
}

