/**
 * @author Ted
 */
/**
 * Harvests all H3 tags on the page to create a table of contents
 */
$(document).ready( function() { sls.legal.toc(); } );

if(!modules) var modules = {};
modules['sls.legal'] = true;

if(!sls) var sls = {};
sls.legal = {};

if(modules['sls.ajax'])
{
	if(!sls.ajax.setup) sls.ajax.setup = {};
	sls.ajax.setup.legalListings = function(){
		$('a[href*="legal:"]').click(function(){
			sls.ajax({
				page: $(this).attr('href').split('/sls/')[1],
				built: false,
				context: 'legal'
			});
			sls.hash.set('page', $(this).attr('href').split('/sls/')[1]);
			return false;
		});
	}
	
	if(sls.ajax.active) sls.setup.legalListings();
}

$(function() { if(!$('link[href*="legal.css"]').length) $('head').append('<link rel="stylesheet" href="/student/orgs/sls/css/legal.css" type="text/css" media="screen, handheld" />' ); else $('link[href*="legal.css"]').attr('rel' , 'stylesheet'); });
sls.legal.toc = function()
{
	if(!$('#toc_placeholder').length) return;
	var headers = $('h3[id]');
	if(!headers.length) return;
	var toc_wrapper = $(document.createElement('div')).attr('id' , 'toc_wrapper').html('<span class="toc_head">Contents</span>');
	var toc = $(document.createElement('ol')).attr('id' , 'toc');
	var top = $(document.createElement('span')).addClass('toc_back').html(' [<a href="#topic" title="back to top">Top</a>]');
	toc_wrapper.append(toc);
	for(var i = 0 ; i < headers.length ; i++)
	{
		toc.append(sls.legal.toc.createEntry(headers[i]));
	}
	headers.append(top);
	$('#toc_placeholder').replaceWith(toc_wrapper);
}

sls.legal.toc.createEntry = function(node)
{
	return $(document.createElement('li')).append($(document.createElement('a')).attr('href' , '#' + node.id).text($(node).text()));
}

