var bgFadeColor			= '#940010';		// color to fade the background to
var bgFadeDuration		= 100;				// duration of the fading process in ms

$(document).ready(
	function (e)
	{
		$('.BgFade').bind('mouseenter', 
			function(e)
			{
				$(this).stopAll();
				var oldBG = $(this).css('background-color');
				
				$(this).bind('mouseleave', {oldbg : oldBG},
					function (e)
					{
						$(this).stopAll();
						$(this).animate(
							{
								backgroundColor:	e.data.oldbg,
							},
							bgFadeDuration,
							function ()
							{
								$(this).unbind('mouseleave');
							}
						);
					}
				);
				
				$(this).animate(
					{
						backgroundColor:	bgFadeColor,
					},
					bgFadeDuration
				);
			}
		);		
	}
);

function bgFade(selector, fadeInColor, duration)
{
	$(selector).bind('mouseenter', 
			function(e)
			{
				$(this).stopAll();
				var oldBG = $(this).css('background-color');
				$(this).bind('mouseleave', {oldbg : oldBG},
					function (e)
					{
						$(this).stopAll();
						$(this).animate(
							{
								backgroundColor:	e.data.oldbg,
							},
							duration,
							function ()
							{
								$(this).unbind('mouseleave');
							}
						);
					}
				);

				$(this).animate(
					{
						backgroundColor:	'#'+fadeInColor,
					},
					duration
				);
			}
		);
}
