/**
 * JavaScript to control the loading of tips on the homepage
 *
 * Requires jQuery JavaScript library
 */

function addTipControls()
{
	$('#tip').append('<p><a class="tipLoader" href="' + window.location.pathname + '">See another tip?</a></p>');
	$('#tip a.tipLoader').click(function()
	{
		$(this).remove();
		$('#tip').find('p').fadeOut(300, replaceTip);
		return false;
	});
}

function loadTip()
{
	$.get('/main/sfl/tips/tips.htm', {}, function(data)
	{
		if (data.length > 0)
		{
			$('#RelatedItems').prepend(data);
			addTipControls();
		}
	});
}

function replaceTip() {
	$('#tip').load('/main/sfl/tips/tips.htm #tip > *', {}, function()
	{
		addTipControls();
	});
}

/**** Page loaded ****/
$(function()
{
	loadTip();
});
/**** /Page loaded ****/