jQuery(document).ready(function() {
	var sidebarHeight = jQuery('#sidebar').height();
	var changeSidebarHeight = function(sidebarHeight) {
		var bodyHeight = jQuery('body').height();
		var maxHeight = Math.max(sidebarHeight, bodyHeight);
		jQuery('#sidebar').height(maxHeight + 'px');
	}
	jQuery('li').next(':first').not('.info').addClass('selected');
	jQuery('li').next().click(function() {
		var li = jQuery(this);
		if (!li.hasClass('info'))
		{
			jQuery('.selected').removeClass('selected');
			li.addClass('selected');
			jQuery.ajax({
				'type': 'POST',
				'url': 'index.php',
				'cache': true,
				'data': {
					'p': li.attr('id')
				},
				'success': function(data) {
					jQuery('div.post').html(data);
					changeSidebarHeight(sidebarHeight);
				}
			});
		}
	});
	jQuery('li.info').hover(function() {
		var offset = jQuery(this).offset();
		var info = jQuery('#info');
		var top = offset.top - (info.height() * 2)
		if (parseInt(top, 10) < 0)
			top = 0;
		info.css('right', '300px');
		info.css('top', top + 'px');
		info.show();
	}, function() {
		jQuery('#info').hide();
	});
	changeSidebarHeight(sidebarHeight);
});
