//Inline HTML Tooltip script: By JavaScript Kit: http://www.javascriptkit.com
//Created: July 10th, 08'
$(document).ready(function(){
	htmltooltip.render();
})

var htmltooltip={
	tipclass: 'htmltooltip',
	anchorclass: 'tooltipanchor',
	fadeeffect: [true, 400],
	anchors: [],
	tooltips: [], //array to contain references to all tooltip DIVs on the page
	hideevents: [],

	positiontip:function($, tipindex, e){
		var anchor=this.anchors[tipindex]
		var tooltip=this.tooltips[tipindex]
		anchor.dimensions={w:anchor.offsetWidth, h:anchor.offsetHeight, offsetx:$(anchor).offset().left, offsety:$(anchor).offset().top}
		var tipx=anchor.dimensions.offsetx-25
		var tipy=anchor.dimensions.offsety+anchor.dimensions.h-102
		$(tooltip).css({left: tipx, top: tipy, padding: '0px'})
	},

	showtip:function($, tipindex, e){
		var tooltip=this.tooltips[tipindex]
		if (this.fadeeffect[0])
			$(tooltip).hide().fadeIn(this.fadeeffect[1])
		else
			$(tooltip).show()
	},

	hidetip:function($, tipindex, e){
		var tooltip=this.tooltips[tipindex]
		if (this.fadeeffect[0])
			$(tooltip).fadeOut(this.fadeeffect[1])
		else
			$(tooltip).hide()
	},

	updateanchordimensions:function($){
		var $anchors=$('.'+htmltooltip.anchorclass)
		$anchors.each(function(index){
			this.dimensions={w:this.offsetWidth, h:this.offsetHeight, offsetx:$(this).offset().left, offsety:$(this).offset().top}
		})
	},

	render:function(){
		jQuery(document).ready(function($){
			htmltooltip.iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
			var $anchors=$('.'+htmltooltip.anchorclass)
			var $tooltips=$('div.'+htmltooltip.tipclass)
			$anchors.each(function(index){ //find all links with "title=htmltooltip" declaration
				this.dimensions={w:this.offsetWidth, h:this.offsetHeight, offsetx:$(this).offset().left, offsety:$(this).offset().top} //store anchor dimensions
				this.tippos=index+' pos' //store index of corresponding tooltip
				var tooltip=$tooltips.eq(index).get(0) //ref corresponding tooltip
				if (tooltip==null) //if no corresponding tooltip found
					return //exist
				tooltip.dimensions={w:tooltip.offsetWidth, h:tooltip.offsetHeight}
				tooltip.tippos=index+' pos'
				$(tooltip).remove().appendTo('body') //add tooltip to end of BODY for easier positioning
				$(tooltip).hover(
					function(e) {
						var tp=parseInt(this.tippos)
						var tm=htmltooltip.hideevents[tp]
						if(tm>0) {
							clearTimeout(tm)
							htmltooltip.hideevents[tp]=0
						}
					},
					function(e) {
						htmltooltip.hidetip($, parseInt(this.tippos), e)
					}
				)
				htmltooltip.tooltips.push(tooltip) //store reference to each tooltip
				htmltooltip.anchors.push(this) //store reference to each anchor
				htmltooltip.hideevents.push(0)
				var $anchor=$(this)
				$anchor.hover(
					function(e){ //onMouseover element
						var tp = parseInt(this.tippos)
						htmltooltip.positiontip($, tp, e)
						htmltooltip.showtip($, tp, e)

					},
					function(e){ //onMouseover element
						var tp=parseInt(this.tippos)
						htmltooltip.hideevents[tp]=setTimeout(function() { htmltooltip.hidetip($, tp, e) }, 700);
					}
				)
				//$(window).bind("resize", function(){htmltooltip.updateanchordimensions($)})
			})
		})
	}
}

