$(document).ready(function(){
	
	tooltip = $("<div id='tooltip'>" +
					"<div class='t'></div>" +
					"<div class='c'>" +
						"<span class='content'></span>" +
					"</div>" +
				"</div>").hide();
	
	$('body').prepend(tooltip);

	$('.help').live('mousemove',function(e) {

		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);
		tooltip.css({top:y,left:x});

	}).live('mouseenter',function(e){
		$(this).css({zIndex:12});
		ttcontent = $(this).attr("helptext");
		tooltip.find('.c').html(ttcontent).parent().stop(true,true).fadeIn();
		
		if(ttcontent.search("img") == -1) {}
		else {
			// are imagine
			tooltip.find(".c").addClass('withimg');
			tooltip.find(".t").addClass('withimg');
		}
		
	}).live('mouseleave',function(e){
		$(this).css({zIndex:'auto'});
		tooltip.stop(true,true).fadeOut(function() {
			$(this).find(".c").removeClass('withimg');
			$(this).find(".t").removeClass('withimg');
		});
	});
	
});

