
var highlight = function(elt) {$(elt).style.backgroundColor = "#ffd700"; }
var unhighlight = function(elt) {$(elt).style.backgroundColor = ""; }


function hl(elementName)
{
	if (elementName == "" || elementName == null)
	{
		return;
	}
	
	var elts = classNameToIds[elementName];
	if (elts != null)
	{
		elts.each(highlight);
	}
}


var removeClassName = function(elt) { Element.removeClassName(elt, "highlight") };

function uhl(elementName)
{
	if (elementName == "" || elementName == null)
	{
		return;
	}	
	
	var elts = classNameToIds[elementName];
	if (elts != null)
	{
		elts.each(unhighlight);
	}
}


// Sparkline		
function Sparkline(containerId, data, legend)
{
	var me = this;
	var context;
	
	var canvasElt = new Element("canvas", 
		{height:me.canvasHeight, width:data.length*me.lineWidth, id:containerId+"_spark"}
	);
	
	$(containerId).insert(canvasElt);
	
	if (!canvasElt.getContext)
	{
		return;
	}
	
	context = canvasElt.getContext("2d");

	// draw legend
	if (legend)
	{
		var drawYear = function(label, x)
		{
			context.fillStyle = "rgba(200,200,200,0.5)";
			context.fillRect(x,me.winHeight,1,me.canvasHeight-me.winHeight);
			context.fillStyle = "rgba(100,100,100,0.5)";
			context.fillText(label, x+2, me.canvasHeight);
		};
	
		// draw legend
		$H(legend).each(function(pair) { drawYear(pair.key, pair.value)});
	}

	// draw sparklines
	var drawLine = function(x,height,color)
	{	
		context.fillStyle = color;
		context.fillRect(x, me.winHeight-height, me.lineWidth, height);
	};
	
	for (var i = 0; i < data.length; i++)
	{
		var c = data.charAt(i);
		
		switch (c)
		{
			case '0' :
				break;
			case 'W' :
				drawLine(me.lineWidth*i, me.winHeight, me.winColor);
				break;
			case 'T' :
				drawLine(me.lineWidth*i, me.topTenHeight, me.topTenColor);
				break;
			case 'M' :
				drawLine(me.lineWidth*i, me.madeCutHeight, me.madeCutColor);
				break;
		}				
	}
}

Sparkline.prototype.canvasHeight = 25;

Sparkline.prototype.winColor = "rgba(0,100,0,1)";
Sparkline.prototype.topTenColor = "rgba(0,200,0,1)"; 
Sparkline.prototype.madeCutColor = "rgba(190,210,176,1)";
Sparkline.prototype.winHeight = 15;

Sparkline.prototype.topTenHeight = 10;
Sparkline.prototype.madeCutHeight = 5;

Sparkline.prototype.lineWidth = 1;
