
var gTrackerVariables = new Array();

function initialiseSelectors()
{
	// set the classes when mouse hovers over
	$('.selButton').hover(function() {
		$(this).addClass('selButtonHover');
	}, function() {
		$(this).removeClass('selButtonHover');
	});
}

function setSelectorRadio(pName, pVar, pFunction, pRecalcPage, pCheckCompletePage, pCat)
{
	gTrackerVariables[pName] = pVar;

	$(".selButton[name='" + pName + "']").click(function() {
		$(".selButton[name='" + pName + "']").removeClass('selButtonSelected');
		$(this).addClass('selButtonSelected');

		var numChars = $(this).attr('name').length;
		var newVal = $(this).attr('id').substr(numChars);

		$('#' + gTrackerVariables[$(this).attr('name')]).val(newVal);

		if (typeof(pFunction) == 'function')
		{
			if (pCat != '' || pCat >= 0)
			{
				pFunction(newVal, pCat);
			}
			else
				pFunction(newVal);
		}

		if (pRecalcPage != '' && pRecalcPage > 0)
		{
			if (typeof(recalculate) == 'function')
			{
				recalculate(pRecalcPage);
			}
		}

		if (pCheckCompletePage != '' && pCheckCompletePage > 0)
		{
			if (typeof(checkPageComplete) == 'function')
			{
				checkPageComplete(pCheckCompletePage);
			}
		}
	});

	if (typeof(pFunction) == 'function')
	{
		if (pCat >= 0)
			pFunction($('#' + pVar).val(), pCat);
		else
			pFunction($('#' + pVar).val());
	}
}

function setSelectorToggle(pName, pVar, pOffText, pOnText, pFunction, pRecalcPage, pCheckCompletePage)
{
	gTrackerVariables[pName] = pVar;

	$('#' + pName).text(pOffText);
	if ($('#' + gTrackerVariables[pName]).val() == '1')
	{
		$('#' + pName).text(pOnText);
	}

	$('#' + pName).unbind('click');
	$('#' + pName).click(function() {
		if ($(this).hasClass('selButtonSelected'))
			$(this).removeClass('selButtonSelected');
		else
			$(this).addClass('selButtonSelected');

		var newVal = 0;
		if ($('#' + gTrackerVariables[$(this).attr('name')]).val() == '1')
		{
			$('#' + gTrackerVariables[$(this).attr('name')]).val('0');
			$(this).text(pOffText);
		}
		else
		{
			$('#' + gTrackerVariables[$(this).attr('name')]).val('1');
			$(this).text(pOnText);
			newVal = 1;
		}

		if (typeof(pFunction) == 'function')
		{
			pFunction(newVal, pName);
		}

		if (pRecalcPage != '' && pRecalcPage > 0)
		{
			if (typeof(recalculate) == 'function')
			{
				recalculate(pRecalcPage);
			}
		}

		if (pCheckCompletePage != '' && pCheckCompletePage > 0)
		{
			if (typeof(checkPageComplete) == 'function')
			{
				checkPageComplete(pCheckCompletePage);
			}
		}
	});

}

$(function()
{
	initialiseSelectors();
});
