var RollTableChart = new Class({
	initialize:function(width, params)
	{
		this.width = width;
		this.labelcol = params.labelcol;
		this.valuecol = params.valuecol;
		this.body = $(params.body);
		this.max = null;
		this.min = null;
		this.hasTip = false;
		this.buildChart();		
	},
	buildChart:function()
	{
		var rows = this.body.getChildren();
		rows.each(this.scanRow,this);
		if (this.hasTip)
		{
			this.ToolTip = new Element('div',{
																	 'class':'rollhbartip',
																	 'styles':{
																		 'position':'absolute',
																		 'display':'none'
																	 }
																	}).
											injectInside(window.document.body);
		}
		rows.each(this.drawRow,this);
	},
	scanRow:function(row)
	{
		var cell = row.cells[this.valuecol];
		var value = cell.innerHTML.toFloat();
		if (this.max==null || value>this.max) this.max = value;
		if (this.min==null || value<this.min) this.min = value;
		if (cell.getProperty('rel') && !this.hasTip) this.hasTip=true;
	},
	drawRow:function(row)
	{
		var cell = row.cells[this.valuecol];
		var value = cell.innerHTML;
		var size = this.body.getSize();
		var width = Math.round(value.toFloat()/this.max*this.width);
		cell.empty();
		var bar = new Element('div',{
														'class':'rollhbar',
														'styles':{
															'float':'left',
															'width':0,
															'overflow':'visible',
															'text-align':'right'
															}
														}).setHTML(value).injectInside(cell);
		if (this.hasTip)
		{
			bar.addEvent('mouseover',function(){ this.showTip(bar); }.bind(this));
			bar.addEvent('mouseout',function(){ this.hideTip(bar); }.bind(this));
		}
		var fx = bar.effects({'wait':true, 'duration': 2000,'transition':Fx.Transitions.Expo.easeOut});
		fx.start({'width':[0,width]});
	},
	showTip:function(bar)
	{
		parent = bar.getParent();
		tip = parent.getProperty('rel');
		if ($defined(tip))
		{
			this.ToolTip.setHTML(Json.evaluate(tip).join('<br />'));
			var pos = bar.getCoordinates();
			this.ToolTip.setStyles({
														 'display':'block',
														 'top':pos.top,
														 'left':pos.right
														 });
		}
	},
	hideTip:function(bar)
	{
		this.ToolTip.setStyle('display','none');
	}
	
});