function Tooltip (tooltipObject){
	var tooltip = tooltipObject;
	var maxh = 150; //Approx heidgt of tooltip
	this.setApproxHeigth = function(height){
		maxh=height;
	}

	function show(e){
		var offsetx = 10;
		var offsety = 10;
		var posx = 0;
		var posy = 0;
		var Width = 0;
		var Height = 0;

		if (!e) var e = window.event;
		if (e.pageX || e.pageY) {
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;

		}
		// posx and posy contain the mouse position relative to the document
		// Do something with this information
		//////////////////////////////////////////////////////////////////
		
		if (typeof pageYOffset != "undefined" && typeof pageXOffset != "undefined"){
			yScroll = pageYOffset;
			xScroll = pageXOffset;
		}
		else if(document.compatMode=="CSS1Compat"){
			yScroll = document.documentElement.scrollTop;
			xScroll = document.documentElement.scrollLeft;
		}
		else{
			yScroll = document.body.scrollTop;
			xScroll = document.body.scrollLeft;
		}
		///////////xScroll and YScroll contains scrols values/////////////
		//////////////////////////////////////////////////////////////////
		
		if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
			Width = window.innerWidth;
			Height = window.innerHeight;
		} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			Width = document.documentElement.clientWidth;
			Height = document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			Width = document.body.clientWidth;
			Height = document.body.clientHeight;
		}
		///////////Width and Height contains windows visible with and height///
		//////////////////////////////////////////////////////////////////////
		
		var bottom_edge = Height+yScroll; //Down edge of windows visible part
		var right_edge = Width+xScroll; //Right edge of windows visible part
		var tooltip_width = parseInt(tooltip.style.width); // Width of toltip
		
		tooltip.style.top = '';		tooltip.style.bottom = '';
		tooltip.style.left = '';	tooltip.style.right = '';

		tooltip.style.display = "block";
		if(offsety + posy + maxh < bottom_edge){
			tooltip.style.top = offsety + posy + "px";
		}
		else{
			tooltip.style.top = offsety + posy - maxh  + "px";
		}

		if(offsetx + posx +  tooltip_width < right_edge){
			tooltip.style.left = offsetx + posx + "px";
		}
		else{
			tooltip.style.right = offsetx  - posx + right_edge  + "px";
		}
		/*tooltip.innerHTML = 'posy: '+posy
		+'<br>maxh:'+maxh
		+'<br>yScroll:'+yScroll
		+'<br>bottom_edge:'+ bottom_edge;*/

	}
	function hide(e){
		tooltip.style.display = "none";
	}
	this.ShowTooltip = function(HTMLcontent) {
		tooltip.innerHTML = HTMLcontent;
		document.onmousemove = show;
	}
	this.HideTooltip = function() {
		document.onmousemove = hide;
	}
}
