function Gauge(id,max,delay) {
	if (!max) max = 100;
	if (!delay) delay = 100;
	var currentValue = max;
	var backValue = max;
	var div0 = $('<div id="'+id+'" />').get(0);
	var div1 = $('<div />').get(0);
	var div2 = $('<div style="float: left" />').get(0);
	var div3 = $('<div />').get(0);
	var maxWidth;
	var timer;
	
	div1.appendChild(div2);
	div1.appendChild(div3);
	div0.appendChild(div1);
	div0.setAttribute('title','Value: '+currentValue);

	this.appendTo = function (elm) {
		elm.appendChild(div0);
		maxWidth = $(div1).width();
		redraw();
	}
	function update() {
		backValue--;
		if (backValue <= currentValue) clearInterval(timer);
		backRedraw();
	}
	function backRedraw() {
		var valuePercent = backValue/max;
		var newWidth = Math.floor(valuePercent*maxWidth);
		if (newWidth == 0) div3.style.visibility = 'hidden';
		else div3.style.visibility = 'visible';
		div3.style.width = newWidth+'px';
	}
	function redraw() {
		var valuePercent = currentValue/max;
		var newWidth = Math.floor(valuePercent*maxWidth);
		if (newWidth == 0) div2.style.visibility = 'hidden';
		else div2.style.visibility = 'visible';
		div2.style.width = newWidth+'px';
	}
	this.increase = function (ammount) {
		this.setValue(parseInt(currentValue)+parseInt(ammount));
	}
	this.recover = function () {
		this.setValue(backValue);
	}
	this.setValue = function (value) {
		if (value > max) value = max;
		if (value < 0) value = 0;
		if (value == currentValue) return;
		currentValue = parseInt(value);
		if (currentValue > backValue) backValue = currentValue;
		redraw();
		clearInterval(timer);
		timer = setInterval(update,delay);
		div0.setAttribute('title','Value: '+currentValue);
	}
	this.getValue = function () {
		return currentValue;
	}
	this.getBackValue = function () {
		return backValue;
	}
	this.setHeight = function (h) {
		div2.style.height = div3.style.height = h+'px';
	}
}

