$(document).ready(function() {
	
	$('#tooltip').fadeTo(0, .0);
	$("[tooltip='']").each(function() {
		$(this).attr('tooltip', $(this).nextAll('span.hidden').html() );
	});
	$('[tooltip]').mouseover(function(ev){
		var vOffset = -30;
		/* compensate in case an existing fade out is still running from a previous mouseout event */
		if($('#tooltip').css('opacity') > 0) {
			$('#tooltip').stop();
		}
		$('#tooltip').html(  $(this).attr('tooltip')  );
		
		/* compensate the offset value in case the tooltip is going to be off the top of the browser view area */
		if(ev.pageY - $('#tooltip').height() + vOffset - $(document).scrollTop() < 10) {
			vOffset = ($('#tooltip').height()+18);
		}
		$('#tooltip').css({'top':(ev.pageY) - $('#tooltip').height() + vOffset, 'left':(ev.pageX) - ($('#tooltip').width()/2) });
		$('#tooltip').fadeTo(250, .9);
		$(this).mousemove(function(ev) {
			$('#tooltip').css({'top':(ev.pageY) - $('#tooltip').height() + vOffset, 'left':(ev.pageX) - ($('#tooltip').width()/2) });
		});
	}); 
	$('[tooltip]').mouseout(function() {
		/* compensate in case an existing fade in is still running from a previous mouseover event */
		if($('#tooltip').css('opacity') < .9) {
			$('#tooltip').stop();
		}
		$('#tooltip').fadeTo(250, .0, function() {
			$('#tooltip').css({'top':-300, 'left':0 });
		});
	});
	
	$('.navbar > a').each(function() {
		if( location.href.indexOf( $(this).attr('href') ) > 0 ) {
			$(this).css({'background-color': '#0D2959'});
		}
	})
	
});
