var ItemsLoader_Counter=0;

function ItemsLoader(id,Limit,Count,Template){
	this.Limit=Limit;
	this.id=id;
	this.Count=Count;
	this.Template=Template;
	this.Loading=false;
}

ItemsLoader.prototype.LoadItems= function(Offset, Callback){	
	if (this.Loading) return;	
	if (Offset>=this.Count) return;//Кончились
	///alert(Offset);
	this.Loading=true;
	
	AjaxRequest_Callback(this.id+'Offset='+Offset+'&Limit='+this.Limit,[],this.OnItemsLoaded_Factory(Callback));
}

ItemsLoader.prototype.LoadItems_Factory= function(){
	var self=this;
	return function(Offset,Callback){		
		self.LoadItems(Offset,Callback);
	}
}

ItemsLoader.prototype.OnItemsLoaded_Factory= function(Callback){
	var self=this;
	return function(resp){
		var Items=[];
		
		for (i=0; i<resp['Nodes'].length; i++){
			Items[Items.length]=self.Template(resp['Nodes'][i],ItemsLoader_Counter);			
//			alert(Items[Items.length]);
			ItemsLoader_Counter++;
		}
		
		Callback(Items);
		self.Loading=false;
	}
}
