// -*- mode: javascript -*-

var jorEconomia = {

	SCALE_SPEED: 50,
	SCALE_INTERVAL: 30,

	objectAlignRight: function (parent, obj) {
		if (obj && obj.clientWidth) {
			var left = parent.clientWidth - obj.clientWidth - 2;
			if (left < 0)
				left = 0;
			obj.style.left = left + "px";
		}
	},

	widgetMove: function (cabezal) {
		var eco = this;
		dodo.delayRun (function () {
			eco.objectAlignRight (cabezal, jorEconomia.finance);
			eco.objectAlignRight (cabezal, jorEconomia.widget);
			jorEconomia.widget.style.visibility = "visible";
		});
	},

	financeScale: function (finance, box, size, dir) {
		size += dir * this.SCALE_INTERVAL;
		if (size <= 0) {
			size = 0;
			box.style.visibility = "hidden";
			dir = 0;
		} else if (size >= this.FINANCE_HEIGHT) {
			size = this.FINANCE_HEIGHT;
			box.style.visibility = "visible";
			dir = 0;
			finance.state = 1;
		}

		finance.style.height = size + "px";

		if (dir) {
			var eco = this;
			dodo.delayRun (function () {
				eco.financeScale (finance, box, size, dir);
			}, this.SCALE_SPEED);
		}
	},

	financeToggle: function (widget, finance, box) {
		if (!finance.state) {
			var eco = this;

			finance.state = 2;
			widget.style.backgroundImage = "url(/imagenes/arriba.gif)";
			finance.style.height = "0px";
			finance.style.visibility = "visible";
			box.style.visibility = "hidden";
			dodo.delayRun (function () {
				jorSection.cabezalResize ();
				dodo.delayRun (function () {
					eco.financeScale (finance, box, 0, 1);
				});
			});
		} else if (finance.state == 1) {
			finance.state = 0;
			widget.style.backgroundImage = "url(/imagenes/abajo.gif)";
			finance.style.visibility = "hidden";
			box.style.visibility = "hidden";
		}
	},

	onLoad: function () {
		var eco = this;

		this.widget = document.getElementById ("indicadores_financieros_widget");
		this.finance = document.getElementById ("indicadores_financieros_main");

		if (this.finance) {
			this.finance_box = document.getElementById ("indicadores_financieros_box");
			this.FINANCE_HEIGHT = this.finance_box.clientHeight;
			this.widget.onclick = function () { eco.financeToggle (eco.widget,
																   eco.finance,
																   eco.finance_box); }
			this.widget.ondblclick = this.widget.onclick;
			this.widget.innerHTML = '<div unselectable="on" class="shadow noselect">indicadores financieros</div><div unselectable="on" class="shadow2 noselect">indicadores financieros</div>';
		} else
			this.widget.style.display = "none";
	}
};

dodo.onLoadPush (function () { jorEconomia.onLoad ();});

