function Dimming()
{
	var div;
	var opacity = 0;
	var direction = -1;
	var timer = null;

	// Set dimming button and over functions
	this.setButton = function(direction)
	{
		// change button
		var bt = document.getElementById("dimming_button");
		if (direction > 0)
		{
			bt.src = "/images/bombilla.png";
			bt.onmouseover = function () { this.src = "/img/buttons/dimming_on.gif"; }
			bt.onmouseout = function () { this.src = "/images/bombilla.png"; }
		}
		else
		{
			bt.src = "/img/buttons/dimming_on.gif";
			bt.onmouseover = function () { this.src = "/images/bombilla.png"; }
			bt.onmouseout = function () { this.src = "/img/buttons/dimming_on.gif"; }
		}
	}

	// Create the dimming div
	this.createDiv = function()
	{
		div = document.createElement("DIV");
		div.style.position = "absolute";
		div.style.left = "0px";
		div.style.top = "0px";
		div.style.width = "100%";
		div.style.height = "100%";
		div.style.backgroundColor = "#000000";
		div.style.zIndex = "8999";
		this.applyOpacity();
		document.body.appendChild(div);

		this.adjustHeight();
	}

	// Remove the dimming div
	this.removeDiv = function()
	{
		document.body.removeChild(div);
		div = null;
	}

	// Appear effect
	this.effect = function()
	{
		if (!div) this.createDiv();

		opacity += 10 * direction;
		opacity = Math.min(Math.max(opacity, 0), 90);
		this.applyOpacity();

		if (opacity < 90 && opacity > 0)
		{
			timer = setTimeout("dimming.effect()", 100);
			return;
		}
		else if (opacity <= 0)
			this.removeDiv();

		timer = null;
	}

	// Toggle display
	this.toggle = function()
	{
		direction = -direction;
		if (!timer) this.effect();

		//dimming.setButton(direction);
	}

	// Set dimming opacity
	this.applyOpacity = function()
	{
		div.style.filter = "alpha(opacity="+opacity+")";
		div.style.opacity = "."+opacity;
		div.style.MozOpacity = "."+opacity;
	}

	// fix height
	this.adjustHeight = function()
	{
		div.style.height = document.documentElement.scrollHeight + "px";
	}
}

var dimming = new Dimming();// SimpleBar Class

