
/**
 * 跟踪查询管理器
 */
var TrackerManager = function (maxThread,tracker,items) {
	this.items = items || [];
	this.maxThread = maxThread || 20;
	this.tracker = tracker;
	this.curCount = 0;
	this.enable = true;
	
	this.reset = function(){
		this.curCount = 0;
		this.items = null;
		this.enable = true;
	}
	
	this.load = function(items){
		this.reset();
		if(typeof items == 'string'){
			this.items = items.split(",").reverse();
		}
	}
	
	this.inc = function(){
		this.curCount ++;
	}
	
	this.dec = function(){
		this.curCount --;
		this.track();
	}
	
	this.check = function(){
		return this.curCount <= this.maxThread;
	}
	
	this.destory = function(){
		this.enable = false;
	}
	
	this.track = function(){
	  var item = "";
	  while( this.enable  &&  this.check() && (item=this.items.pop())!=null ){
	  	if(tracker != null ){
			tracker.call(this,item);
	  	}else{
	  		alert("tracker is null! ");
	  		break;
	  	}
		this.inc();
	  }
	}
	
	this.finish = function(){
		if(this.items==null) return true;
		return this.items.length<=0;
	}
	
	this.push = function(itemid){
		if(this.items==null){
			this.items = new Array();
		}
		if(this.finish()){
			this.items.push(itemid);
			this.track();
		}else{
			this.items.push(itemid);
		}
	}
}
