
	var cartIsShowing;
	var userLoggedIn;

	$(document).ready(function()
	{
		prepareButtons();
		cartIsShowing = $('#cartButton').length > 0;
		userLoggedIn = $('#loggedInDiv').length > 0;
		if (cartIsShowing || userLoggedIn)
		{
			$('#outerCartMenu').show();
			$('#topMarginForCart').show();
			$('#notLoggedInDiv').show();
		}
		$('.hoverSame').hover(
			function()
			{
				var FID = $(this).attr('class').match(/FID(\d+)/)[1];
				var FIID = $(this).attr('class').match(/FIID(\d+)/)[1];
				//$('.FID'+FID).addClass('otherHighlight');
				$(this).addClass('thisHighlight');
				//$('#changeCart_Add_'+FIID).show();
			},
			function()
			{
				var FID = $(this).attr('class').match(/FID(\d+)/)[1];
				var FIID = $(this).attr('class').match(/FIID(\d+)/)[1];
				//$('.FID'+FID).removeClass('otherHighlight');
				$(this).removeClass('thisHighlight');
				//$('#changeCart_Add_'+FIID).hide();
				//$('#btnText_Add_'+FIID).button("destroy");
			});
			$('#functionList').change(function()
			{
				filterCourses($(this));
			});
	});

function filterCourses(ctrl)
{
	var FID = ctrl.val();
	//$('.hoverSame').show();
	if (FID == '')
	{
		$('.hoverSame').show();
	}
	else
	{
		$('.FID'+FID).show();
		$('.hoverSame').not('.FID'+FID).hide();
	}
}

function prepareButtons()
{
		$('span[id^="changeCart_"]').click(function()
		{
			var btn = $(this);
			var id = $(this).attr("id").split('_');
			var action = id[1];
			var FunctionInstanceID = id[2];
			var otherFn = "Add";
			var verb = "removed from";

			if (action == "Add")
			{
				otherFn = "Remove";
				verb = "added to";
			}

			$('#btnText_'+action+'_'+FunctionInstanceID).html('wait...');

			 $.ajax({                
			 	type: "POST",                
				url: "/data_access/cart_update.php",                
				cache: false,                
				data: "Action="+action+"&FunctionInstanceID="+FunctionInstanceID,                
				success: function(msg)
				{
					btn.hide();
					$('#btnText_'+action+'_'+FunctionInstanceID).html(action);
					$('#changeCart_'+otherFn+'_'+FunctionInstanceID).show();
					msg = msg.split('|');
					var NumReg = parseInt(msg[1]);
					if (NumReg == 0)
					{
						if (cartIsShowing)
						{
							$('#cartButton').slideUp('slow');
							$.jGrowl('Your cart has been emptied',{life: 5000});
							if (!userLoggedIn)
							{
								$('#topMarginForCart').hide('slow', function()
								{
									//$('#outerCartMenu').hide();
								});
								$('#notLoggedInDiv').hide('slow');
								//start at 40 in case it hasn't been visible yet...
								$('#jGrowl').css('top','40px').animate({'top': '0px'}, 'slow');
							}
							else
								$('#jGrowl').css('top','40px');
						}
						cartIsShowing = false;
					}
					else
					{
						if (!cartIsShowing)
						{
							hideVal = ' display: none;';
						}
						else
							hideVal = '';
						$('#cartSpan').html('<a id="cartButton" class="button" href="/cart.php" style="margin: 5px; color: white;'+hideVal+'"><img src="/images/cart.png" alt="Shopping cart" border="0" style="vertical-align: -3px;"> Your cart: '+NumReg+' item'+s(NumReg)+'</'+'a>');
						$('#cartButton').button();
						if (!cartIsShowing)
						{
							$('#cartButton, #outerCartMenu').slideDown();
							$('#topMarginForCart').show('slow');
							$('#notLoggedInDiv').show('slow');
							//$('#cartButton').slideDown();
							//$('#userMsgSpan').html("Click here to complete your registration:").delay(1000).fadeIn('slow').delay(5000).fadeOut();
							//$.jGrowl("Click the cart button above to complete your registration",{life: 10000});
							var btnText = '<a id="cartButtonDemo" class="button" href="/cart.php" style="margin: 5px; color: white;"><img src="/images/cart.png" alt="Shopping cart" border="0" style="vertical-align: -3px;"> Your cart: '+NumReg+' item'+s(NumReg)+'</'+'a>';

							$('body').append('<div id="checkOutNotice"><p align="center">To check out, click the</p><p align="center">'+btnText+'</p><p align="center">button in the upper-right corner of your screen.</p><p align="center">You can also continue moving through the site, adding items to your cart.</p></div>');
							$('#cartButtonDemo').button();
							$('#checkOutNotice').dialog(
								{
								        modal: true,
										width: 400,
										height: 320,
								        draggable: false,
								        resizable: false,
								        buttons:
								        {
								                OK: function()
								                {
								                        $( this ).dialog( "close" );
								                }
								        }
								}
							);
							$('#jGrowl').animate({'top': '40px'}, 'slow');
						}
						else
						{
							//$('#userMsgSpan').html("Item "+verb+" your cart").stop(true,true).fadeIn('slow').delay(3000).fadeOut();
							$.jGrowl("The item has been "+verb+" your cart");
							$('#jGrowl').css('top','40px');
						}
						cartIsShowing = true;
					}
                }        	
			});	
		});
}
function s(num)
{
	if (num+0 != 1)
		return "s";
	else
		return "";
}
