//Ajax Tooltip script: By JavaScript Kit: http://www.javascriptkit.com
//Last update (July 10th, 08'): Modified tooltip to follow mouse, added Ajax "loading" message.
//====================================================================
//Update by Alexander Ageyev (Ageev in translit notation) at 2008.12.11
// tooltip loaded from "tooltip" attribute from ANY tag
// var and file names changed for avioding conflict with original library
var aatooltip={
	fadeeffect: [false, 300], //enable Fade? [true/false, duration_milliseconds]
	useroffset: [10, 10], //additional x and y offset of tooltip from mouse cursor, respectively
//	loadingHTML: '<div style="font-style:italic"><img src="ajaxload.gif" /> Fetching Tooltip...</div>',

	positiontip:function($tooltip, e){
		var docwidth=(window.innerWidth)? window.innerWidth-15 : aatooltip.iebody.clientWidth-15
		var docheight=(window.innerHeight)? window.innerHeight-18 : aatooltip.iebody.clientHeight-15
		var twidth=$tooltip.get(0).offsetWidth
		var theight=$tooltip.get(0).offsetHeight
		var tipx=e.pageX+this.useroffset[0]
		var tipy=e.pageY+this.useroffset[1]
		tipx=(e.clientX+twidth>docwidth)? tipx-twidth-(2*this.useroffset[0]) : tipx //account for right edge
		tipy=(e.clientY+theight>docheight)? tipy-theight-(2*this.useroffset[0]) : tipy //account for bottom edge
		$tooltip.css({left: tipx, top: tipy})
	},

	showtip:function($tooltip, e){
		if (this.fadeeffect[0])
			$tooltip.hide().fadeIn(this.fadeeffect[1])
		else
			$tooltip.show()
	},

	hidetip:function($tooltip, e){
		if (this.fadeeffect[0])
			$tooltip.fadeOut(this.fadeeffect[1])
		else
			$tooltip.hide()
	}
}

jQuery(document).ready(function(){
	aatooltip.iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	$('<div id=aaToolTipDiv class="aatooltip"></div>').appendTo('body')
	$('*[@tooltip]').each(function(){ //find all tags with "tooltip=" declaration
		var $target=$(this)
		$target.hover(
			function(e){ //onMouseover element
				var $tooltip=$("#aaToolTipDiv")
        $tooltip.html($(this).attr("tooltip"))
        aatooltip.positiontip($tooltip, e)
        aatooltip.showtip($tooltip, e)
			},
			function(e){ //onMouseout element
				var $tooltip=$("#aaToolTipDiv")
				aatooltip.hidetip($tooltip, e)
			}
		)
		$target.bind("mousemove", function(e){
		  var $tooltip=$("#aaToolTipDiv")
			aatooltip.positiontip($tooltip, e)
		})
	})
})

