var repeater = new Class({
    initialize: function(DataSource, Target){
    	this.datasource=DataSource;
		this.ObjectTarget=Target;
		this.currentRow=0;
		this.pageSize=20000;
		this.rowTemplate='';
		this.rowTemplateAlt='';
		this.pageingTemplate='';
		this.NoItemsTemplate='';
		this.ConditionalSeparatorTemplate='';
		this.ConditionalSeparatorTemplateCondition=null;
		this.ConditionalSeparatorTemplateConditionValue='';

    },
	dataSource: function(value)
	{
		    this.datasource=value;
	},
	target: function(value)
	{
		    this.ObjectTarget=value;
	},
	
	buildPage: function()
	{	    
		var data=this.datasource.getView();	    
		var strOutput=" ";
		var j=0;
		if (this.rowTemplateAlt.length==0)
		{
			this.rowTemplateAlt=this.rowTemplate
		}
		var alt=0;

		data.each(function(item, index){	
			if (index>=this.currentRow && index<this.currentRow + this.pageSize)
			{
				if (this.ConditionalSeparatorTemplateCondition!=null)
				{
					//alert(item.lastini + "-" + item[this.datasource.getColID('lastini')] + ', ' + this.ConditionalSeparatorTemplateConditionValue + ', ' + this.datasource.getColID('lastini'));
					if (this.ConditionalSeparatorTemplateCondition(item.associate(this.datasource.colNamesArray), this.datasource, this.ConditionalSeparatorTemplateConditionValue))
					{
						//alert('Condition true');
						strOutput=strOutput + this.buildRow(this.ConditionalSeparatorTemplate, item);
						alt=0;
					}
				}
			
				if (alt==0)
				{
					strOutput=strOutput + this.buildRow(this.rowTemplate, item);
					alt=1;
				}else
				{
					strOutput=strOutput + this.buildRow(this.rowTemplateAlt, item);
					alt=0;
				}
			}
			j++;
		}, this);
		
		if (j<1)
		{
			strOutput=strOutput + this.NoItemsTemplate; 
		}
		if (j>this.currentRow + this.pageSize && this.pageingTemplate.length>0)
		{
			strOutput=strOutput + this.pageingTemplate
		}
		$(this.ObjectTarget).innerHTML= this.headTemplate +  strOutput + this.footTemplate ;
	},
	
	buildRow: function(sTemplate, data)
	{			
		//return sTemplate.substitute(data.associate(this.datasource.colNamesArray)).replace('[itemData]', data.associate(this.datasource.colNamesArray));
		return sTemplate.substitute(data.associate(this.datasource.colNamesArray));			
	},
	
	setRowTemplate: function(value)
	{
		this.rowTemplate=value;
	},
		
	setRowTemplateAlt: function(value)
	{
		this.rowTemplateAlt=value;
	},
	
	setHeaderTemplate: function(value)
	{
		this.headTemplate=value;
	},
	
	setFooterTemplate: function(value)
	{
		this.footTemplate=value;
	},
	setConditionalSeparatorTemplate: function(value, condition)
	{
		this.ConditionalSeparatorTemplate=value;
		this.ConditionalSeparatorTemplateCondition=condition;
	},
	setNoItemsTemplate: function(value)
	{
		this.NoItemsTemplate=value;
	},
	tempFunction: function()
	{
		return "true";
	},
	setPageingTemplate: function(value)
	{
		this.pageingTemplate=value;
	},
	moveNext: function ()
	{
		this.currentRow=this.currentRow + this.pageSize;
		this.buildPage();
	}
	
});
