// ------------------------------------
// Tooltip object.
// ------------------------------------

function ClassToolTip()
{ 
	this.tipElements = ['a'];					// Array of allowable elements for toolTips
	this.obj = Object;							// Current element that youre hovering over
	this.tip = Object;							// The actual toolTip DIV itself
	this.OffsetX = 200;
	this.Initialize = function ()
	{
		if (!document.getElementById || !document.createElement || !document.getElementsByTagName )
		{
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		this.tip.className = 'tooltip_container';
		this.tip.style.width = 272 + 'px';
		
		var sHtml = '\
			<div style="width:431px;">\
				<div class="hover_left">&nbsp;</div>\
				<div style="float:right; width:415px;">\
				<table cellpadding="0" cellspacing="0">\
				<tr>\
					<td class="vi_hover_upper_left_corner" height="10"></td>\
					<td background="'+Settings.RootPath+'images/vacancies/hover_upper_bg.gif" style="background-repeat:repeat-x;" height="10"></td>\
					<td class="vi_hover_upper_right_corner" height="10"></td>\
				</tr>\
				<tr>\
					<td width="380" height="100" colspan="2" bgcolor="#ffffff">\
						<div class="hover_container" style="height:100px;">\
							<div class="hover_right" style="width:400px;">\
								<div class="hover_contents">\
									<div class="index_vacancy_container">\
										<div class="index_vacancy_logobox" style="height:100px;"><a href="#"><img id="data3" src="" border="0"></a></div>\
										<div class="index_vacancy_infobox">\
											<div class="index_vacancy_infobox_title" style="height:30px;"><a href="#" id="data0" class="fp_vacancy_title"></a></div>\
											<div><img src="'+Settings.RootPath+'images/spacer.gif" width="1" height="10"></div>\
											<div class="index_vacancy_infobox_level_label" style="clear:both;"><a href="#" class="fp_vacancy_level_label">Bedrijf:</a></div>\
											<span class="fp_vacancy_level"><a href="#" id="data1" class="fp_vacancy_level"></a></span><br />\
											<div><img src="'+Settings.RootPath+'images/spacer.gif" width="1" height="5"></div>\
											<div class="index_vacancy_infobox_location_label" style="clear:both;"><a href="#" class="fp_vacancy_location_label">Plaats: </a></div>\
											<span class="fp_vacancy_level"><a href="#" id="data2" class="fp_vacancy_location"></a></span>\
										</div>\
									</div>\
								</div>\
							</div>\
						</div>\
					</td>\
					<td width="10" class="vi_hover_right_bg" height="10"></td>\
				</tr>\
				<tr>\
					<td width="10" class="vi_hover_left_corner" height="10"></td>\
					<td width="390" class="vi_hover_bottom" height="10"></td>\
					<td width="10" class="vi_hover_bottom_right_corner" height="10"></td>\
				</tr>\
				</table>\
				</div>\
			</div>\
		</div>';
		
		this.tip.innerHTML = sHtml;
		
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';

		var tipLen = this.tipElements.length;
		for ( i=0; i<tipLen; i++ )
		{
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ )
			{
				if(current[j].title)
				{
					AddEvent(current[j], "mouseover", function(evt) { return TipOver(evt); }, true);
					AddEvent(current[j], "mouseout", function(evt) { return TipOut(evt); }, true);
					
					current[j].setAttribute('tip', current[j].title);
					current[j].removeAttribute('title');
				}
			}
		}
	}
  
  	this.ShowTip = function ()
	{
		var Ttop, Tleft, ClientWidth, ClientHeight, ScrollTop;
		var TipWidth, TipHeight;

		if (this.obj.getAttribute('tip').length == 0)
		{
			return;
		}  
		
		Tleft = findPosX(this.obj);		// offsetLeft;
		Ttop = findPosY(this.obj);		// offsetTop;
		TipWidth = this.tip.offsetWidth;
		TipHeight = this.tip.offsetHeight;
		
		if (self.innerHeight)
		{
			// all except Explorer
			ClientWidth = self.innerWidth;
			ClientHeight = self.innerHeight;
			ScrollTop = self.scrollTop;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{
			ClientWidth = document.documentElement.clientWidth;
			ClientHeight = document.documentElement.clientHeight;
			ScrollTop = document.documentElement.scrollTop;
		}
		else if (document.body)
		{
			// other Explorers
			ClientWidth = document.body.clientWidth;
			ClientHeight = document.body.clientHeight;
			ScrollTop = document.body.scrollTop;
		}
		
		var data = this.obj.getAttribute('tip').split(';');
		document.getElementById('data0').innerHTML = data[0];
		document.getElementById('data1').innerHTML = data[1];
		document.getElementById('data2').innerHTML = data[2];
		document.getElementById('data3').src = data[3];
		
		Tleft = Tleft + this.OffsetX;

		if ((Tleft + TipWidth) > ClientWidth) Tleft = ClientWidth - TipWidth;
		if (Tleft < 1) Tleft = 1;
		if (Ttop < 1) Ttop = 1;
		if (Ttop < ScrollTop) Ttop = ScrollTop + (TipHeight + 5);
		
		this.tip.style.left = Tleft + 'px';
		this.tip.style.top = Ttop + 'px';
		this.tip.style.visibility = 'visible';
	}
}

function TipOut ()
{
	ToolTip.tip.style.visibility = 'hidden';
}

function TipOver (evt)
{
	ToolTip.obj = (evt.target) ? evt.target : evt.srcElement;
	ToolTip.ShowTip();
}