var g_dropdownMarkerImage = new Image();
g_dropdownMarkerImage.src = '/images/cmp_dropdown_marker.gif';

var g_dropdownOpenedMarkerImage = new Image();
g_dropdownOpenedMarkerImage.src = '/images/cmp_dropdown_opened_marker.gif';

var DETAILS_TOOLTIP_ADDITIONAL_TOP_OFFSET = 4;

function UpdateAccountTypeHighlighterHeight()
{
	$("#compare_free_pro_highlighter").css("height", $("#compare_free_pro").height() + "px");
}

function ShowAccountTypeHighlighter(highlighter)
{
	var highlighter = $(highlighter);
	if (!highlighter.is(":visible"))
	{
		UpdateAccountTypeHighlighterHeight();
		highlighter.show();
	}
}

function HighlightProAccountType()
{
	var highlighter = $("#compare_free_pro_highlighter");
	if (!highlighter.size())
	{
		return;
	}
	
	ShowAccountTypeHighlighter(highlighter);
	
	var offset = $("#pro_account_column").offset();
	if (jQuery.browser.mozilla)
	{
		++(offset.left);
	}
	
	highlighter.css("left", offset.left + "px");
}

function HighlightFreeAccountType()
{
	var highlighter = $("#compare_free_pro_highlighter");
	if (!highlighter.size())
	{
		return;
	}
	
	ShowAccountTypeHighlighter(highlighter);
	
	var offset = $("#free_account_column").offset();
	if (jQuery.browser.mozilla)
	{
		++(offset.left);
	}
	
	highlighter.css("left", offset.left + "px");
}

function HideAccountTypeHighlighter(compareTableId)
{
	$("#compare_free_pro_highlighter").hide();
}

function HideFeatureDetailsTooltip(callback)
{
	var tooltip = $("#detailsTooltip");
	tooltip.stop(true, true);
	tooltip.data("hidding", true);
	tooltip.fadeOut("fast", callback);
}

function ShowFeatureDetailsTooltip(element, detailsElementId)
{
	function onHideFeatureDetailsTooltip()
	{
		var tooltip = $("#detailsTooltip");
		tooltip.data("hidding", false);
		
		element = $(element);
		var offset = element.offset();
		
		tooltip.find(".details").html($("#" + detailsElementId).html());
		tooltip.css("left", offset.left + "px");
		tooltip.css("top", (offset.top + element.height()) + DETAILS_TOOLTIP_ADDITIONAL_TOP_OFFSET + "px");
		tooltip.fadeIn("normal");
	}
	
	var tooltip = $("#detailsTooltip");
	if (tooltip.is(":visible") && !tooltip.data("hidding"))
	{
		HideFeatureDetailsTooltip(onHideFeatureDetailsTooltip);
	}
	else
	{
		if (tooltip.data("hidding"))
		{
			tooltip.stop(true, true);
		}
		onHideFeatureDetailsTooltip();
	}
}

function InitFeatureDetailsTooltip(featureTitleElement)
{	
	featureTitleElement = $(featureTitleElement);
	var detailsId = featureTitleElement.siblings(".details").attr("id");
	if (!detailsId)
	{
		return;
	}
	
	featureTitleElement.find("a").hover (
												function () 
												{
													ShowFeatureDetailsTooltip(this, detailsId);
												}, 
												function ()
												{
													HideFeatureDetailsTooltip();
												}
										);
}

$(document).ready
(
	function ()
	{
		$("table.cmp_free_pro div.feature_title").each(function () { InitFeatureDetailsTooltip(this); });
	}
);
