$(document).ready(function() {
		
	$('.helpInfo:not(.helpInfoBlock)').prepend('<h2>Help</h2> ');
	$('.helpInfoBlock').prepend('<h2>Help</h2>');

	//initially hide all help items
	$('.helpInfo').hide();
	
	// append a question mark on any object that needs help displayed
	$('.help').each(function(index) {
		link = '<a href="#" class="helpButton" onclick="return toggleHelp(' + index;
		link += ');"><span>?</span></a>';
		$(this).after(link);
	});

	// if there is an extra float class, place absolute positioning on the
	// helpInfo
	$('.helpInfo.helpInfoFloat').each(function(index) {
		var posLeft = $('.help:eq(' + index + ')').position().left + 200;
		$(this).css('position', 'absolute');
		$(this).css('left', posLeft);
	});
	
	$('.helpInfo.helpInfoFloatLeft').each(function(index) {
		var posLeft = $('.help:eq(' + index + ')').position().left + 170;
		$(this).css('position', 'absolute');
		$(this).css('left', posLeft);
	});

	// add close buttons
	$('.helpInfo').each(function(index) {
		link = '<a href="#" class="helpClose" onclick="return toggleHelp(' + index;
		link += ');"><span>X</span></a>';

		$(this).css({left: $('.helpButton:eq(' + index + ')').position().left + 27});
		$(this).css({top: $('.helpButton:eq(' + index + ')').position().top + 5});
	
		var content = $(this).html();

		content = '<span class="helpInfoText">' + content + '</span>';
		$(this).html(content);
		$(this).find('h2').html($(this).find('h2').html() + link);
	});
});


function toggleHelp(index)
{
	// hide all of the help before any are shown
	$('.helpInfo:not(:eq(' + index + '))').hide();

	if($('.helpInfo:eq(' + index + ')').css('display') == 'none')
	{
		$('.helpInfo:eq(' + index + ')').show();
	}
	else
	{
		$('.helpInfo:eq(' + index + ')').hide();
	}

	return false;
}
