var Termo = new Class.create ({
	initialize: function (value) {
		this.termo   = $ ('termo')
		this.mercure = $ ('mercure')
		this.actual  = value || 0;
		this.h = null;
	},

	depl: function (p) {
		this.actual = p;
		this.mercure.setStyle ({'width': p + "%"});
	},

	up: function (end) {
		if (this.actual < end)
			this.h =setTimeout (function () {
				this.depl (this.actual + 2);
				this.up (end);
			}.bind (this), 20)
	},
	
	down: function (end) {
		if (this.actual > end)
			this.h = setTimeout (function () {
				this.depl (this.actual - 2);
				this.down (end);
			}.bind (this), 20)
	},

	req: function (v) {
		new Ajax.Request ('?action=ajax_termo&v=' + v);
	},
	
	m: function (end) {
		if (end == this.actual)
			return;
		clearTimeout (this.h);
		this.req (end);
		if (this.actual < end)
			this.up (end);
		else
			if (this.actual > end)
				this.down (end);
	}
});

var Termo2 = new Class.create (Termo, {
	initialize: function (e, value) {
		this.termo = e;
		this.mercure = Selector.findChildElements(e, ['[id=mercure]']).first();
		
		this.actual  = value || 0;
		this.h = null;
	},
	depl: function (p) {
		this.actual = p;
		$(this.mercure).setStyle ({'width': p + '%'});
	},
	req: function (v, e) {
		this.value = v;
	},
	m: function ($super, v, e) {
		if (typeof(e) != 'undefined') {
			Selector.findChildElements(this.termo, ['a']).invoke('setStyle', {'color': 'black'});
			$(e).setStyle({'color': 'red'});
		}
		$super(v);
	}
});
