
$(document).ready(function() {

	$('a[rel=tooltip]').mouseover(function(e) {

		var id = $(this).attr('id');
		$(this).attr('title','');
		$(this).children('.tooltip').css('display','inline');
		
	}).mousemove(function(e) {
		var positioning = $(this).attr('class').split('_');
		var pos_x = positioning[1];
		var pos_y = positioning[0];
		var scroll_x = document.getElementById('scroller').scrollLeft;
		var scroll_y = document.getElementById('scroller').scrollTop;
		var window_x = document.body.clientWidth;
		var window_y = document.body.clientHeight;
		
		var xed = e.pageX - (window_x-600)/2 - pos_x*2 + scroll_x;
		
		if (e.pageX > window_x/2+110) { xed -= 180; }
		
		$(this).children('.tooltip').css('top', e.pageY-60-pos_y);
		$(this).children('.tooltip').css('left',xed);
		// + e.pageX + scroll_x - pos_x);
		
		//$(this).children('.tooltip').html('');
		//$(this).children('.tooltip').append(window_x/2 + ' ' + e.pageX + '  ' + scroll_x + '  '  + ' :  ' +xed);
		//$(this).children('.tooltip').append('<br/>' + window_y + ' ' + e.pageY + '  ' + scroll_y + '  '  + ' :  ' +pos_y);

	}).mouseout(function() {
		$(this).attr('title',$(this).children('.tooltip').html());
		$(this).children('.tooltip').css('display','none');
	
	});

});
