/* (c) 2005 Field of View (www.fov.ru) */
function ToolTip(){	this.__construct=function(){		this.browser=CLR.GetUserAgentInfo();
		this.classProp=(this.browser.engine=='MSIE')?'className':'class';
		var images=document.getElementsByTagName('IMG');
		for(var i=0; i<images.length; i++){			image=images[i];
			if((image.getAttribute(this.classProp)=='tooltip')&&(attr=image.getAttribute('tooltip'))&&(m=attr.match(/ID\:(\w+)/))&&(tooltip=CLR.GetObject(m[1]))){				this.AssignTooltip(image,tooltip);
			}
		}
	};

	this.AssignTooltip=function(object,tooltip){		object.tooltip=tooltip;
		if(object.tagName=='IMG'){			object.removeAttribute('alt');
		}
		if(object.parentNode.tagName=='A'){			object.parentNode.removeAttribute('title');
		}
		var self=this;
		var over=function(e){			self.OnMouseOver(e);
		};
		var out=function(e){			self.OnMouseOut(e);
		};
		var move=function(e){			self.OnMouseMove(e);
		};
		CLR.AddEvent(object,'onmouseover',over);
		CLR.AddEvent(object,'onmouseout',out);
		CLR.AddEvent(object,'onmousemove',move);
	};

	this.OnMouseOver=function(e){		tooltip=e.target.tooltip;
		tooltip.style.display='block';
	};

	this.OnMouseOut=function(e){		tooltip=e.target.tooltip;
		tooltip.style.display='none';
	};

	this.OnMouseMove=function(e){		tooltip=e.target.tooltip;
		x=window.event?event.clientX+document.body.scrollLeft:e.pageX;
		y=window.event?event.clientY+document.body.scrollTop:e.pageY;
		screenw=document.body.clientWidth;
		screenh=document.body.clientHeight;
		offsetx=document.body.scrollLeft;
		offsety=document.body.scrollTop;
		ttwidth=tooltip.offsetWidth;
		ttheight=tooltip.offsetHeight;
		marginx=16;
		marginy=16;
		spaceLeft=x-offsetx-marginx;
		spaceRight=offsetx+screenw-x;
		spaceTop=y-offsety-marginy;
		spaceBottom=offsety+screenh-y;
		canBeLeft=(x-offsetx-marginx>=ttwidth);
		canBeRight=(x<=offsetx+screenw-marginx-ttwidth);
		canBeTop=(y-offsety-marginy>=ttheight);
		canBeBottom=(y<=offsety+screenh-marginy-ttheight);
		if(!canBeLeft&&!canBeRight){			canBeLeft=(spaceLeft>spaceRight);
			canBeRight=!canBeLeft;
		}
		if(!canBeTop&&!canBeBottom){			canBeTop=(spaceTop>spaceBottom);
			canBeBottom=!canBeTop;
			if(spaceTop>spaceBottom){				y=y+(ttheight-spaceTop);
			}
			else{				y=y-(ttheight-spaceBottom);
			}
		}
		if(canBeBottom&&canBeRight){			ptop=y+marginy;
			pleft=x+marginx;
		}
		else
			if(canBeBottom){				ptop=y+marginy;
				pleft=x-ttwidth-marginx;
			}
			else
				if(canBeRight){					ptop=y-ttheight-marginy;
					pleft=x+marginx;
				}
				else{					ptop=y-ttheight-marginy;
					pleft=x-ttwidth-marginx;
				}
		if(ptop)
			tooltip.style.left=pleft+'px';
		tooltip.style.top=ptop+'px';
	};

	this.__construct();
}

