
// Définition de la classe 'CarSelectorItem'
// NB: L'ordre des méthodes est important

CarSelectorItem.Instances = new Array();

function CarSelectorItem(id)
{
	// Outil pour récupérer une instance par son identifiant
	CarSelectorItem.Instances[id] = this;

	this.HtmlObject = document.getElementById(id);

	// Champs privés
	var idParts = id.split("__");
	var _arrow = document.getElementById(id + "__Arrow");
	var _images = this.HtmlObject.getElementsByTagName("img");
	var _arrowLeft = 0, _arrowWidth = 0, _imagesLeft;
	var _top = 0;
		
	// Propriétés
	this.Id = id;
	this.Model = idParts[1];
	this.GrBodyStyle = idParts[2];
	this.PriceLabel = "";
	this.NeverShown = true;
	this.OnClick = new Array();
	this.OnOver = new Array();
	this.OnOut = new Array();

	this.IsVisible = function()
	{
		return (this.HtmlObject.style.display != "none");
	}

	this.OnItemClick = function(item)
	{
		var args =
		{
			Model: this.Model,
			GrBodyStyle: this.GrBodyStyle,
			PriceLabel: this.PriceLabel
		};
		
		Tools_DispatchEvent(this.OnClick, this, args);
	}
	
	this.OnItemOver = function(e, item)
	{
		var evt = e ? e : event;
	
		var args =
		{
			MouseLeft: evt.clientX,
			MouseTop: evt.clientY,
			Model: this.Model,
			GrBodyStyle: this.GrBodyStyle,
			PriceLabel: this.PriceLabel
		};
		
		Tools_DispatchEvent(this.OnOver, this, args);
	}
	
	this.OnItemOut = function(item)
	{
		var args =
		{
			Model: this.Model,
			GrBodyStyle: this.GrBodyStyle,
			PriceLabel: this.PriceLabel
		};
		
		Tools_DispatchEvent(this.OnOut, this, args);
	}

	this.Show = function()
	{
		this.HtmlObject.style.display = "block";
		if (document.body.className == "IE6")
			Tools_ForEach(_images, function(image)
			{
				image.style.width = image.offsetWidth + "px";
				image.style.height = image.offsetHeight + "px";
				doFix(image);
			});
		this.NeverShown = false;
	}

	this.Hide = function()
	{
		this.HtmlObject.style.display = "none";
	}

	this.SetPriceLabel = function(priceLabel)
	{
		this.PriceLabel = priceLabel;
	}

	this.SetDescription = function(description)
	{
		this.HtmlObject.title = description;
	}

	this.GetImagesSize = function()
	{
		return { ThumbWidth: _images[0].offsetWidth, LabelWidth: _images[1].offsetWidth, Height: _images[0].offsetHeight	};
	}

	this.GetImagesLeft = function()
	{
		return _imagesLeft;
	}

	this.GetArrowSize = function()
	{
		return { Left: _arrowLeft, Width: _arrowWidth };
	}

	this.SetArrowSize = function(left, width)
	{
		_arrowLeft = left;
		_arrowWidth = width;
		_arrow.style.left = left + "px";
		_arrow.style.width = width + "px";

//		var margin = (this.HtmlObject.offsetHeight + _arrow.offsetHeight) / 2;
//		if (document.body.className != "IE6" && document.body.className != "IE7" /*  && document.body.className != "IE8" */)
//			margin -= _images[0].offsetHeight;
//		_arrow.style.marginTop = margin + "px";
	}

	this.SetImagesLeft = function(left)
	{
		_imagesLeft = left;
		_images[0].style.left = left + "px";
		_images[1].style.left = left + "px";
	}
}
