/*
 * Implements the product spotlight functionality
 */

$("li", "ul.prod_spotlight").mouseenter(toggleActive);
setActive($("ul.prod_spotlight > li:first"));
toggleActive.last = $("ul.prod_spotlight > li:first");

function toggleActive()
{
	// reset previous
	if (toggleActive.last != null)
	{
		$('div.spacer', toggleActive.last).removeClass('prod_arrow');	
		$('div.prod_thumb', toggleActive.last).removeClass('prod_thumb_active');	
	}

	setActive(this);
	toggleActive.last = this;
}

function setActive(elm)
{
	$('div.spacer', elm).addClass('prod_arrow');	
	$('div.prod_thumb', elm).addClass('prod_thumb_active');	
	showMessage(elm);
}

function getTextLength(elm)
{
	return $('a', $('p', elm)).html().length;
}

function showMessage(elm)
{
	var firstItem = $('ul.prod_spotlight > li:first').position().left;
	var totalWidth = $('.prod_spotlight').width();
	var totalWidth = $('.prod_spotlight').width();
	var start = $(elm).position().left - firstItem;
	var textWidth = getTextLength(elm) * 7;

	if (start + textWidth > totalWidth)
		start = totalWidth - textWidth;

	$('.prod_description').empty();
	var descr = $('p', elm).clone();
	descr.css('margin-left', start);
	$('.prod_description').append(descr);	
}
