//Inline HTML Tooltip script: By JavaScript Kit: http://www.javascriptkit.com
//Created: July 10th, 08'

// Edit by Michal Kandr (www.kandr.name) 12.10.2008

var htmltooltip={
	tipclass: 'htmltooltip',
	fadeeffect: [true, 500],
	anchors: [],
	tooltips: [], //array to contain references to all tooltip DIVs on the page

	positiontip:function($, tipindex, e){
		var anchor=this.anchors[tipindex]
		var tooltip=this.tooltips[tipindex]
		
		var aOffset = $(anchor).offset();
		var tipx = aOffset.left-$(tooltip).width();
		var tipy = aOffset.top;
		if($.browser.mozilla){
			tipy += 1;
			tipx += 1;
		} else if($.browser.msie) {
			tipy -= 2;
			tipx -= 2;
		}
		
		$(tooltip).css({left: tipx, top: tipy})
	},

	showtip:function($, tipindex, e){
		//zavreni ostatnich
		var i=0;
		$(this.tooltips).each(function(tooltip){
			htmltooltip.hidetip($,i++,e);
		});
		//otevreni pozadovaneho
		var tooltip=this.tooltips[tipindex]
		if (this.fadeeffect[0])
			$(tooltip).hide().fadeIn(this.fadeeffect[1])
		else
			$(tooltip).show()		
		$(this.anchors[tipindex]).addClass('objFormHelpHover');
	},

	hidetip:function($, tipindex, e){
		var tooltip=this.tooltips[tipindex]
		if (this.fadeeffect[0])
			$(tooltip).fadeOut(this.fadeeffect[1])
		else
			$(tooltip).hide()
		$(this.anchors[tipindex]).removeClass('objFormHelpHover');
	},

	updateanchordimensions:function($){
		var $anchors=$('*[@rel="'+htmltooltip.tipclass+'"]')
		$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=$('*[@rel="'+htmltooltip.tipclass+'"]')
			var $tooltips=$('div[@class="'+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.tippos=index+' pos' //store index of corresponding tooltip
				tooltip.dimensions={w:tooltip.offsetWidth, h:tooltip.offsetHeight}
				$(tooltip).remove().appendTo('body') //add tooltip to end of BODY for easier positioning
				//$(tooltip).prepend('<p class="helpBoxClose"><a href="#"><span>x</span> zavřít</a></p>');
				htmltooltip.tooltips.push(tooltip) //store reference to each tooltip
				htmltooltip.anchors.push(this) //store reference to each anchor
				var $anchor=$(this)
				$anchor.click(
					function(e){ //onMouseover element
						htmltooltip.positiontip($, parseInt(this.tippos), e)
						htmltooltip.showtip($, parseInt(this.tippos), e)
						return false
					}
				)
				$(window).bind("resize", function(){htmltooltip.updateanchordimensions($)})
			})
			$('.helpBoxClose a').click(function(e){
				htmltooltip.hidetip($, parseInt($($(this).parent().get(0)).parent().get(0).tippos), e)
				return false;
			});
		})
	}
}

htmltooltip.render()