$(document).ready(function(){
	
	//$('#tooltip').remove();
	
	tooltip = $("<div id='tooltip'>" +
					"<div class='t'></div>" +
					"<div class='c'>" +
						"<span class='title'>Sample</span>" +
						"<span class='content'>Lorem ipsum dolor sit amet consectetuer adipiscing elit sed diam nonummy!</span>" +
					"</div>" +
				"</div>").hide();
	
	$('body').prepend(tooltip);
	
	
	
	$('.help').attr('title','').mousemove(function(e){
		//$('title').html(tooltip.height());
		
		var cond = (e.pageY-tooltip.height() < $(window).scrollTop());
		
		var y = (cond ? $(window).scrollTop() : e.pageY-tooltip.height()-10);
		var x = (cond ? e.pageX+10 : e.pageX-15);
		
		/*console.log(e.pageY-tooltip.height()+20 < $(window).scrollTop());*/
		
		tooltip.css({top:y,left:x});
		
		
		
	}).mouseenter(function(e){
		$(this).css({zIndex:12});
		ttcontent = $(this).find('.tooltip');
		tooltip.find('.c').html(ttcontent.html()).parent().stop(true,true).fadeIn();
		if(ttcontent.find('img').length > 0) {
			tooltip.addClass('withimg');
			//$('title').html('are img');
		} else {
			//$('title').html('nu are img');
		}
	}).mouseleave(function(e){
		$(this).css({zIndex:'auto'});
		tooltip.stop(true,true).fadeOut(function() {
			$(this).removeClass('withimg');
		});
	});
	
});
