/*
 * magic.js
 * Last Revision: August 11, 2010
 * 
 * Main JS file for site
 */

$(function() {
	$('a.footnote-link').click(function() {
		$('#footnotes_container li, ul.footnotes li').removeClass('selected-footnote');
		$('#fn-' + $(this).text()).parents('li').addClass('selected-footnote');
	});
	
	$('#copyright').after(
		$(document.createElement('section')).attr('id', 'link-hrefs').append(
			$(document.createElement('h1')).text('External Links')
		).append(
			$(document.createElement('ol'))
		)
	);

	$('.link-notes a[href!=""]').not('[class*="no-ref"]').each(function(i) {
		var href = $(this).attr('href');
		var superscript = $(document.createElement('sup')).text(i + 1).addClass('link-ref');

		if(href.indexOf('/') == 0) { href = 'http://tachyondecay.net' + href; }
		if($(this).hasClass('block-link')) {
			$(this).children().first().append(superscript);
		}
		else {
			$(this).after(superscript);
		}

		$('#link-hrefs ol').append($(document.createElement('li')).text(href));
	});
	
	$('#my-calendar dd.title').hide();
	$('#my-calendar dl.calendar-event').attr('title', 'Click for more details.').addClass('cal-js').click(function () {
		$(this).children('dd.title').toggle();
	});
});