/*
 * jQuery Tooltip 0.1.3
 *
 * Copyright (c) 2008 Vytenis Kuciauskas
 *
 * @description: Use <a href="#(hiden div ID)">[?]</a>
 * @example: 
 * <a href="#help" class="help"><img src="css/help.png" alt="[?]" width="21" height="21" hspace="5" style="vertical-align:middle" /></a>
 * <div id="help" class="tooltip" style="display:none">Help content</div>
 *
 */
var timer = 'belekas';
function init_tooltips() {
	var tooltips = [];
	tooltips = $('a[href^=#][class=help]');
	
	tooltips.click(function(){ 
		return false;
	});
	
	tooltips.hover(
		function(event) {
			var tooltip = $($(this).attr("href"));
			
			var ofsetx = 0;	//tooltip.width();
			var ofsety = 0;	//tooltip.height();

			var mouseX = event.pageX
			var mouseY = event.pageY
			
			var winWidth = $(window).width();
			var winHeight = $(window).height();

			mouseX -= (tooltip.width()-ofsetx+10)/2;
			mouseY -= (tooltip.height()-ofsety+10)/2;

			if ($(document).scrollTop()+tooltip.height() > event.pageY) {
				mouseY = $(document).scrollTop()+5;
			}
			
			if (event.clientX + tooltip.width() > winWidth) {
				mouseX = winWidth - tooltip.width()-15;
			}
			
			tooltip.appendTo("body").css({
				"left": mouseX + "px",
				"top": mouseY + "px",
				"zindex": 9999,
				"cursor": "help"
			});
			
			timer = window.setTimeout(function(){
				tooltip_show(tooltip);
			},500);
			
		},function() {
			window.clearTimeout(timer);
		});
	jQuery(document).bind("click",function() {
		$('.tooltip').fadeOut('slow');
	});

}
$(document).ready(function(){
	init_tooltips();
});
function tooltip_show(what) {
	what.fadeIn('slow');
	what.unbind('hover');
	what.bind("mouseleave", function(e){
		$(this).fadeOut('slow');
	});
	what.unbind("hover");
	//alert(timer);
	window.clearTimeout(timer);
}

