function select_app(app_num) {
	var AppClass = ".App"+app_num;
	var AppClassArray = $(AppClass);
	var MenuItemId = "#MenuItemApp"+app_num;
	var SelectedProductClass = ".mfSelectedProduct";
	var SelectedProductArray = $(SelectedProductClass);
	var model_num = null;
	var currentTime = new Date();
	var expires = null;

	//Time out after 10 minutes (minutes*seconds*milliseconds)
	currentTime.setTime(currentTime.getTime()+(10*60*1000));
	expires = "; expires="+currentTime.toGMTString();

	//Set current value of application cookie
	document.cookie = 'SelectedApp='+app_num+'; '+expires+"; path=/";

	
	//Only proceed if current application is not already selected
	if (!$(MenuItemId).hasClass("mfSelectedMenuItem"))
	{
		//Toggle all previously selected items to 'OFF'
		$.each(SelectedProductArray, function(index, value) {
			model_num = value.id.substring(9);

			$(value).removeClass('mfSelectedProduct');
			toggle_product(model_num, 'OFF', true);
		});
		
		//Clear any previously selected menu items
		$(".mfSelectedMenuItem").removeClass("mfSelectedMenuItem");

		//Select current menu item
		$(MenuItemId).addClass("mfSelectedMenuItem");

		//Select appropriate products
		$.each(AppClassArray, function(index, value) {
			model_num = value.id.substring(9);
			
			toggle_product(model_num, 'ON', true);
			$(value).addClass('mfSelectedProduct');
		});
	}
}

function toggle_app(app_num, status) {
	var SelectedProductArray = $('.mfSelectedProduct');
	var HighlightedApplicationArray = $('.App'+app_num);
	
	var SelectedAppNum = null;
	var model_num = null;

	//Determine ID of currently selected app
	$.each($('.mfSelectedMenuItem'), function(index, value) {
		SelectedAppNum = value.id.substring(11);
	});
	

	//onmouseover
	if (status=='ON')
	{
		//Clear selected products if not currently highlighted
		$.each($(SelectedProductArray), function(index, value) {
			if (!$(value).hasClass('App'+app_num))
			{
				model_num = value.id.substring(9);
				toggle_product(model_num, 'OFF', true);
			}
		});

		//Toggle products for currently highlighted application,
		//Skip remaining currently-selected items (since they will be highlighted already)
		$.each($(HighlightedApplicationArray), function(index, value) {
			if (!$(value).hasClass('App'+SelectedAppNum))
			{
				model_num = value.id.substring(9);
				toggle_product(model_num, 'ON', true); 
			}
		});
	}
	//onmouseout
	else if (status=='OFF')
	{
		//Clear all highlighted products that were not previously selected
		$.each($(HighlightedApplicationArray), function(index, value) {
			if (!$(value).hasClass('App'+SelectedAppNum))
			{
				model_num = value.id.substring(9);
				toggle_product(model_num, 'OFF', true); 
			}
		});

		//Re-select previously selected products
		$.each($(SelectedProductArray), function(index, value) {
			if (!$(value).hasClass('App'+app_num))
			{
				model_num = value.id.substring(9);
				toggle_product(model_num, 'ON', true);
			}
		});

	}
}

function toggle_product(model_num, status, change_selected_products) {
	var productId = '#mfProduct'+model_num;
	var image = document.getElementById('mfImage'+model_num);
	var new_img = '/images/products/Apex'+model_num+'/Apex'+model_num+'-mic_finder-'+status+'.jpg';

	//Since this function can be called from highlighting a product or highlighting/selecting an application,
	//different behaviour is expected.  Only proceed if allowed to change currently-selected items
	if (!$(productId).hasClass('mfSelectedProduct') || change_selected_products==true)
	{
		if (status=='ON')
		{
			$(productId).addClass('mfHighlightedProduct');
		} else if (status=='OFF')
		{
			$(productId).removeClass('mfHighlightedProduct');
		}

		image.src = new_img;
	}
}
