/* sidebar : from Dotclear.org, thanks to Olivier Meunier */
$(function() {
	/* get the children of #blognav and #blogextra at the same level */
	$('#sidebar>div>div').each(function() {
		if ($(this).find('h2').length > 0) {
			/* ignore widgets without h2, they will be ignored after */
			$('#sidebar').append($(this).get(0));
		}
	});
	
	/* remove #blognav and #blogextra */
	$('#blognav,#blogextra').remove();
	
	$('#top').after($('#sidebar').addClass('sidebar'));
	$('#sidebar>div').hide();
	
	var list = $('<ul class="sidebar"></ul>');
	var item, link;
	$('#sidebar>div h2').each(function() {
		link = document.createElement('a');
		link.href = '#';
		link.target_element = $(this).parent().get(0);
		$(link).append($(this).text());
		item = document.createElement('li');
		$(item).append(link);
		
		$(link).click(function() {
			$(list).find('li>a').not(this).each(function() {
				$(this.target_element).slideUp(100);
			});
			$(this.target_element).slideToggle(100);
			return false;
		});
		
		list.append(item);
	});
	list.find('li:last').addClass('last');
	$('#sidebar').before(list);
	
	$('#sidebar').css({'margin':'0','padding':'0 1em'});
	
	if ($('input#q').val() != '') {
		$('div#search').show();
	}


	/* thanks to Olivier Meunier */
	if ($('body.dc-post, body.dc-page').length == 0) { return; }
	if ($('#pr').length > 0) { return; }
	
	var link = $('<a href="#">' + $('#comment-form h3:first').text() + '</a>').click(function() {
		$('#comment-form fieldset').show(200);
		$('#c_name').focus();
		$(this).parent().html($(this).text());
		return false;
	});
	$('#comment-form h3:first').empty().append(link);
	$('#comment-form fieldset').hide();
});
