$(document).ready(function() {
	$("#menu li").mouseover(function() {		
		$(this).addClass("over");
		//alert(1);
	})	
	$("#menu li").mouseout(function() {		
		$(this).removeClass("over")
	})
	$('a[rel=tooltip]').mouseover(function(e) {
		var id = $(this).attr('id');  
		var tip = $(this).attr('title');   
		$(this).attr('title','');
		$('#tooltip-place').append('<table cellspacing="0" cellpadding="0" border="0" class="tooltip" id="tooltip-'+id+'"><tr><td class="t1">&nbsp;</td><td class="t2">&nbsp;</td><td class="t3">&nbsp;</td></tr><tr><td class="t4">&nbsp;</td><td class="t5"><div class="tooltip-info">'+tip+'</div></td><td class="t6">&nbsp;</td></tr><tr><td class="t7">&nbsp;</td><td class="t8">&nbsp;</td><td class="t9">&nbsp;</td></tr></table>');    		
        $('#tooltip-'+id+'').css('left',position('X',id,e.pageX));
        $('#tooltip-'+id+'').css('top',position('Y',id,e.pageY));		
	}).mousemove(function(e) {
		var id = $(this).attr('id');
		$('#tooltip-'+id+'').css('left',position('X',id,e.pageX));
        $('#tooltip-'+id+'').css('top',position('Y',id,e.pageY));
		$('#mX').val(e.pageX)
		$('#mY').val(e.pageY)
	}).mouseout(function() {
		var id = $(this).attr('id'); 
	//	alert($('#tooltip-'+id+' .tooltip-info').html())
        $(this).attr('title',$('#tooltip-'+id+' .tooltip-info').html());
        $('#tooltip-place').children('table.tooltip').remove();
	});
});

function position(pivot,id,val){
	var nr;
	var difX,difY
	var sC = 3;
	var tWidth =  $('#tooltip-'+id+'').width();
	var tHeight =  $('#tooltip-'+id+'').height();
		
	switch(pivot){
		case 'X':			
			if((val + tWidth)>$(window).width()){
				difX = (tWidth + sC) * -1;
			}else{
				difX = sC;
			}
			nr = val + sC + difX;
		break;
		case 'Y':
			if((val + tHeight)>$(window).height()){
				difY = (tHeight + sC) * -1;
			}else{
				difY = sC;
			}
			nr = val + difY;
		break;
	}
	return nr;
}
