 $(function() {

	$('.ttbutton').mouseover(function(e){
		var url = $(this).attr('url');
		createTT(url,e);
	});
	
	$('.ttbutton').mouseout(function(e){
		var url = $(this).attr('url');
		deleteTT();
	});
 	
});

function setMouseOver(){
	$('.ttbutton').mouseover(function(e){
		var url = $(this).attr('url');
		createTT(url,e);
	});
	
	$('.ttbutton').mouseout(function(e){
		var url = $(this).attr('url');
		deleteTT();
	});
}

function createTT(ptURL,e){
	var rootview = $(window).scrollTop();
	var rootwidth = $('#root').width();
	var rootheight = $(window).height();
	var rootX = $('#root').offset().left;

	$('body').append("<div id=\"tooltip\"></div>");
	$('#tooltip').hide();
	
	$(document).mousemove(function(e){
		var rootwidth = $('#root').width();
		var rootheight = $(window).height();
		var rootview = $(window).scrollTop();
		var rootX = $('#root').offset().left;
		$('#tooltip').css({
			//top: Math.min((e.pageY + 15),rootview + rootheight-$('#tooltip').height()) + "px",
			//left: (e.pageX > rootwidth + rootX -$('#tooltip').width()) ? (e.pageX -$('#tooltip').width() - 5) + "px" : (e.pageX + 15) + "px"
			top: Math.min((e.pageY - 395),rootview + rootheight-$('#tooltip').height()) + "px",
			left: rootX+340
		});
	});
	$('#tooltip').load(ptURL, function(data){ 
		$(this).show();
		$(this).css({
			//top: Math.min((e.pageY + 15),rootview + rootheight-$('#tooltip').height()) + "px",
			//left: (e.pageX > rootwidth + rootX -$('#tooltip').width()) ? (e.pageX -$('#tooltip').width() - 5) + "px" : (e.pageX + 15) + "px"
			top: Math.min((e.pageY - 395),rootview + rootheight-$('#tooltip').height()) + "px",
			left: rootX+340
		});
	});
}

function deleteTT(){
	$(document).unbind('mousemove');
	$('#tooltip').remove();
}
