function scrollToTop () {
    $.scrollTo($('#page'), 1000) ;
};

function makeTOC () {
    var headingsList = [] ;
    var sectionIndex = 0 ;
    $('h2').each(function (index) {
	headingsList.push($(this).html());
	$(this).attr({ id: 'sec_' + sectionIndex.toString(),
		       onclick: 'scrollToTop();',
		       title: 'Click to return to top' }) ;
	sectionIndex++ ;
    });
    for (i=0; i < sectionIndex; i++) {
	$('#toccontent').append('<li><a href="#sec_' + i.toString() + '">' + headingsList[i] + '<\/a><\/li>') ;
    };
};

$(function () {
    $('div.sd_embed').hide() ;
    $('div.cv-item > span.clickme').toggle(function() {
	$(this).html('<span class="clickme-link">Click<\/span> to hide presentation');
	$(this).parent().children('div.sd_embed').show('blind', {direction: 'vertical'}, 1000 ) ;
    }, function () {
	$(this).html('<span class="clickme-link">Click<\/span> to view presentation');
	$(this).parent().children('div.sd_embed').hide('blind', {direction: 'vertical'}, 1000 ) ;
    });
	makeTOC() ;
    $('#toc').localScroll() ;
});

