
// Définition de la classe 'CarSelectorTooltip'
// NB: L'ordre des méthodes est important

CarSelectorTooltip.Instances = new Array();

function CarSelectorTooltip(id)
{
	// Outil pour récupérer une instance par son identifiant
	CarSelectorTooltip.Instances[id] = this;
		
	// Champs privés
	var _timerId = null;
	var _xMin = 0, _xMax = Infinity;
	var _yMin = 0, _yMax = Infinity;
	var _content = document.getElementById(id + "Content");
	var _left = document.getElementById(id + "Left");
	var _currentX = 0, _currentY = 0, _currentTargetHeight = 0;
	
	// Propriétés publiques
	this.HtmlObject = document.getElementById(id);

	// Méthodes publiques
		
	this.SetText = function(text)
	{
		_content.innerHTML = text;
	}

	this.SetContainer = function(obj)
	{
		if (obj != null)
		{
			var position = Tools_GetPosition(obj);
			_xMin = position.Left;
			_xMax = _xMin + obj.offsetWidth;
			_yMin = position.Top;
			_yMax = _yMin + obj.offsetHeight;
		}
	}
	
	this.UpdateCorners = function()
	{
		// Supprime les bords arrondis en cours
		if (this.HtmlObject != null)
			Tools_ForEach(this.HtmlObject.getElementsByTagName("div"), function(div)
			{
				while (div.firstChild && div.firstChild.className == "niftycorners")
				{
					div.style.paddingTop = div.style.paddingBottom;
					div.removeChild(div.firstChild);
				}
			});
	}
	
	// targetHeight est optionnel
	this.SetPosition = function(x, y, targetHeight)
	{
		_currentX = x;
		_currentY = y;
		_currentTargetHeight = targetHeight;

		if (x == 0)
			x = $(".CarSelectorChart").position().left;

		this.HtmlObject.style.left = x + "px";
		this.HtmlObject.style.top = (y - this.HtmlObject.offsetHeight / 2) + "px";
	}
	
	// duration est optionnel
	this.Show = function(duration)
	{
		if (duration)
		{
			if (_timerId != null)
				clearTimeout(_timerId);
			_timerId = setTimeout(this.Hide, duration);
		}
	
		this.UpdateCorners();
		this.HtmlObject.style.display = "block";
		
		// Pour corriger un bug de positionnement...
		this.SetPosition(_currentX, _currentY, _currentTargetHeight);
	}
	
	this.Hide = function()
	{
		_timerId = null;
		this.HtmlObject.style.display = "none";
	}
	
	this.IsVisible = function()
	{
		return (this.HtmlObject.style.display == "block");
	}
	
	this.GetPosition = function()
	{
		return { X: _currentX, Y: _currentY, TargetHeight: _currentTargetHeight };
	}
}
