$(document).ready(function() {
	
	$('body').append('<div id="tooltip"><div id="tipbody"><h3></h3><p></p></div><div id="tiptail"></div></div>');
	
	function show_tip(e){
		if($('#tipbody p a').length>0){
			var text = $('#tipbody p a').text();
			$('#tipbody p').html(text);
		}
		var tt_height = $('#tooltip').height();
		$('#tooltip').show();
		$('#tooltip').css('top', e.pageY-(tt_height+5));
		$('#tooltip').css('left', e.pageX-15);
	}
	function hide_tip(){
		$('#tooltip').hide();
		$('#tipbody h3, #tipbody p').empty();
	}
	
	$('.category-twitter').bind('mouseover', function(e){
		$(this).find('.time').clone().appendTo('#tipbody h3');
		$(this).find('.entry').clone().appendTo('#tipbody p');
		show_tip(e);
	});
	$('.category-vimeo, .category-reware-vintage-blog, .category-night-cam').bind('mouseover', function(e){
		$(this).find('.time').clone().appendTo('#tipbody h3');
		$(this).find('h2 a').clone().appendTo('#tipbody p');
		show_tip(e);
	});
	$('.category-lastfm').bind('mouseover', function(e){
		$(this).find('.time').clone().appendTo('#tipbody h3');
		$(this).find('h2 a').clone().appendTo('#tipbody p');
		var author = $(this).find('.author').text();
		$('#tipbody p a').prepend(author+' listened to ');
		show_tip(e);
	});
	$('.category-delicious').bind('mouseover', function(e){
		$(this).find('.time').clone().appendTo('#tipbody h3');
		$(this).find('h2 a').clone().appendTo('#tipbody p');
		var author = $(this).find('.author').text();
		$('#tipbody p a').prepend(author+' bookmarked ');
		show_tip(e);
	});
	$('.category-flickr').bind('mouseover', function(e){
		$(this).find('.time').clone().appendTo('#tipbody h3');
		$(this).find('img').clone().appendTo('#tipbody p');
		show_tip(e);
	});
	
	$('.category-twitter, .category-lastfm, .category-flickr, .category-vimeo, .category-delicious, .category-reware-vintage-blog, .category-night-cam').bind('mouseout', function(){
		hide_tip();
	});
});
