var contentsState = false;

function switchContentsState(state) {
	contentsState = state;
	setTimeout('setContentsState()', 10);
}

function setContentsState() {
	$('#contentsbox').css('display', contentsState ? 'block' : '');
}

$(document).ready(function() {
	var el;
	var el1;
	
	el = $('<div />');
	el.attr('id', 'contentsicon');
	el.mouseenter(function() { switchContentsState(true); });
	el.mouseleave(function() { switchContentsState(false); });
	el.appendTo('body');
	
	el = $('<div />');
	el.attr('id', 'contentsbox');
	el.mouseenter(function() { switchContentsState(true); });
	el.mouseleave(function() { switchContentsState(false); });
	el.appendTo('body');
	
	el = $('<div />');
	el.addClass('top');
	el.text('Contents');
	el.appendTo('#contentsbox');
	
	$('#content').children('h2, h3, h4').each(function(i) {
		el = $('<div />');
		el.addClass(this.tagName.toLowerCase());
		el.appendTo('#contentsbox');
		el1 = $('<a />');
		el1.attr('href', '#' + this.id);
		el1.text($(this).text());
		el1.appendTo(el);
	});
});
