<!-- Student & Parent portal: add the Merit Store link when the school is enabled and the audience
     pref allows it.

     The school test is done in JS rather than with [if ... in (...)]: the "in" form does not
     evaluate on the guardian portal, so wrapping this script in one meant the link never rendered
     at all. [displaypref] and (curschoolid) both work here, so the CSV check is just string work.
     Comma-wrapping both sides keeps the match exact, so 34 never matches 340. -->
<script>
	$j(function() {
		var schoolOk = (',~[displaypref:meritStoreEnabledSchools],').indexOf(',~(curschoolid),') > -1;
		var aud = '~[wc:meritstore/meritPrefAudience]';
		var isG = ~[if#mg.isguardian]true[else#mg]false[/if#mg];
		var ok = schoolOk && ((aud === 'both') || (aud === 'students' && !isG) || (aud === 'guardians' && isG));
		if (ok) {
			$j('#nav-main ul:first').append('<li id="btn-meritStore" role="menuitem"><a href="/guardian/meritStore.html"><span class="screen_readers_only"></span>Merit Store</a></li>');
			// meritStore.svg is 27x27; scale it up to sit with the ~40px built-in nav icons
			// (matches the district's own psfit icon, which uses background-size:40px 40px).
			$j('#btn-meritStore a').css({ 'background-image': 'url(/images/meritStore.svg)', 'background-size': '40px 40px' });
		}
	});
</script>
