//Author Prabeen Giri(www.prabeengiri.com.np)...........
window.onload = function()
{ 
	var x ; 
	var y ; 
	var titles ;
	var documentWidth = document.body.offsetWidth; 
	var classess = document.getElementsByTagName("*");
	for(i = 0 ; i< classess.length; i++)
	{ 
		if (classess[i].className.match([" "]))
		{ 
 		  var classNames = checkClassName(classess[i].className); 
		} 
		if (classess[i].className=='tooltip' || classNames == 'tooltip')
		{ 
			classess[i].onmousemove = getCoordinates; 
			titles = classess[i].getAttribute('title');
			classess[i].setAttribute('dir',titles);
			classess[i].removeAttribute('title'); 
			classess[i].onmouseout = function () 
			{ 
			 	//to hide the tooltip if the mouse is out from the anchor tag with class  = 'tooltip' 
				document.getElementById('spanBox').style.display = 'none' ; 
			} 
		} 
	}
	// creates the span for tooltip where html change as per hovered node. 
	createDiv();	  
	function showDiv(tl)
	{ 
	
		var t = document.getElementById('spanBox'); 
		t.lastChild.innerHTML = tl; 
				//t.innerHTML = tl; 
	
		z = eval(y) + 25;
	
		r = eval(x) - 15; 
		
		if (r < 0 ) 
			r = 3; 
		//if (r >  (documentWidth-20 ))
			//r= (documentWidth-350 ); 	  
		
		
		t.style.display='block'; 
	
		// to make dynamic position of the tooltip 
	
		t.style.top = z + "px"; 
	
		t.style.left = r + "px"; 
	
		
	
	} 
	function checkClassName(name)
	{ 
		names  = name.split(' ');
		for(var i=0; i < names.length; i++)
		{ 
			if (names[i] == 'tooltip')
			{ 
				return names[i]; 
			} 
		} 
	}
	function getCoordinates (ev)
	
	{ 
	
		// for ie 
	
		if (!ev) ev = window.event ;  
	
		//firefox
	
		if (ev.pageX || ev.pageY) 
	
		{ 
	
			x = ev.pageX; 
	
			y = ev.pageY; 
	
		} 
	
		//IE
	
		else if (ev.clientX || ev.clientY)
	
		{ 
	
			x = ev.clientX ;
	
			y = ev.clientY ;
	
		}
	
		showDiv(this.getAttribute('dir'));
	
	}
	
	
	
	function createDiv() 
	
	{ 
	
		// creates new span element with 
	
		var spn = document.createElement("span"); 
		// sets id as toolTips for span element
		spn.setAttribute('id','spanBox'); 
	
		//css for span element
		spn.style.cssText =  "font-family:'Arial';color:#333333;position:absolute;font-size:11px;border-top:none;max-width:300px;background:url(t_t.gif) no-repeat left top;padding-top:11px;" ;
	
		spn.style.display = 'none'; 
	
		// appends the span element on the last of the body tag.
		var _span = document.createElement('span'); 
		_span.style.cssText = ' display: block;background-color:#FAF9C0;padding:0px;border:1px solid #E1D9A8;border-top:none;padding:8px;'; 
	
	
		spn.appendChild(_span); 
		document.body.appendChild(spn);
	}  
} 


