/**
USES tTemplates;
**/

function tTooltipDefaultConf()
{
	this.zIndex = 251;
	this.fontsize = 12;
	this.top = 20;
	this.left = -40;
	this.color = '#ffff00';
	this.bordercolor="black";
	this.pointsize = 15;
	this.blankimage = '/_layout/default/blank.gif';
	this.timeout=2000;
}



function tTooltip()
{
	//define the templates!
	_tT.define('tooltipinside','<table cellspacing=\'0\' cellpadding=\'0\'><tr><td width="5" height="5"><img src="/_layout/corners/images/corner_5_{color}_tl.png" height="5" width="5"/></td><td  style="background-color:#{color};font-size:1px;">&#160;</td><td  width="5" height="5"><img src="/_layout/corners/images/corner_5_{color}_tr.png" height="5" width="5"/></td></tr><tr><td style="background-color:#{color};font-size:1px;">&#160;</td><td style="background-color:#{color};{style};padding:2px;">{text}</td><td style="background-color:#{color};font-size:1px;">&#160;</td></tr><tr><td  width="5" height="5"><img src="/_layout/corners/images/corner_5_{color}_bl.png" height="5" width="5"/></td><td  style="background-color:#{color};font-size:1px;">&#160;</td><td  width="5" height="5"><img src="/_layout/corners/images/corner_5_{color}_br.png" height="5" width="5"/></td></tr></table>');	
}


tTooltip.prototype.init = function(config)
{
	this.defaultconfig = new tTooltipDefaultConf();
	
	this.tooltips= new Array();
	
	this.config = config;
	if(typeof this.config =='object')
	{
		//its an object at least...
	}
	else
	{
		//whoops well make it then
		this.config = new Array();
	}
	
	//check each setting or set it to defaults
	for (var i in this.defaultconfig)
	{
		if(typeof this.config[i]=='undefined')
		{
			this.config[i] = this.defaultconfig[i];
		}
		
	}

	
}

tTooltip.prototype.checkdiv = function()
{
	
	if(!this.tdiv)
	{
		
		bdy = document.getElementsByTagName('body').item(0);
		//make a new element to contain the tooltip
		tdiv = document.createElement('div');
		tdiv.setAttribute('id','ttooltip');
		tdiv.style.display='none';
		tdiv.style.position='absolute';
		tdiv.style.top='0px';
		tdiv.style.left='0px';
		tdiv.style.zIndex=this.config.zIndex;
		tdiv.innerHTML='empty';
		bdy.appendChild(tdiv);
		tdiv = document.getElementById('ttooltip');
		document.onmousemove = function (e) {_toolTip.updatepos (e)};
		this.tdiv = document.getElementById('ttooltip');
		
		tdiv2 = document.createElement('div');
		tdiv2.setAttribute('id','ttooltip2');
		tdiv2.style.display='none';
		tdiv2.style.position='absolute';
		tdiv2.style.top='0px';
		tdiv2.style.left='0px';
		tdiv2.style.zIndex=this.config.zIndex;
		tdiv2.innerHTML='empty';
		bdy.appendChild(tdiv2);
		tdiv2 = document.getElementById('ttooltip');
		document.onmousemove = function (e) {_toolTip.updatepos (e)};
		this.tdiv2 = document.getElementById('ttooltip2');		
		
	}
	
}





tTooltip.prototype.updatepos = function(e)
{
	


	
	
	var mouseposx=0, y=0;
	if (document.all) {
		//Interne exploder
		mouseposx = ((document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft)+window.event.clientX;
		mouseposy = ((document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop)+window.event.clientY;
	} 
	else 
	{
		mouseposx = e.pageX;
		mouseposy = e.pageY;
	}
	this.tdiv.style.left = (mouseposx + this.config.left) + "px";
	this.tdiv.style.top = (mouseposy + this.config.top) + "px";
	if(this.isactive)
	{
		this.tdiv.style.display='block';
	}
	else
	{
		this.tdiv.style.display='none';
	}
	
}


tTooltip.prototype.drawpointything = function(direction,width,height)
{
	ht ='';
	sdirection='right'
	
	
	style='margin-left:30px;';
	
	
	
	if(direction=='right')
	{
		ht +='<div style="text-align:'+direction+';">';
		sdirection = 'left';
		if(width!='undefined')
		{
			style = 'padding-left:'+(width-30)+'px;padding-right:30px;';
			
		}			
	}
	else
	{
		ht +='<div style="text-align:left;">';
		sdirection = 'right';
	}
	
	
	if(typeof height !='undefined')
	{
		maxval = height;
	}
	else
	{
		maxval = this.config.pointsize;
	}	
	
	ht+='<table cellspacing=\'0\' cellpadding=\'0\' width="'+maxval+'" style="'+style+'">';

	for(gg=1;gg<maxval;gg++)
	{
		
		ht+='<tr><td  height="1" align="'+sdirection+'" style="text-align:'+sdirection+'"><img src="'+this.currentdata.blankimage+'" style="background-color:#'+this.currentdata.color+';" width="'+gg+'" height="1" align="'+sdirection+'"/></td></tr>';
	}
	ht +='</table>';
	ht +='</div>';
	
	return ht;
	
}
tTooltip.prototype.showsticky = function(element,data)
{
	clearTimeout(this.to);
	
	this.checkdiv();
	
	if((typeof element =='object')&&(typeof data =='object'))
	{
		this.currentelement = element
		for (var i in this.defaultconfig)
		{
			if(typeof data[i]=='undefined')
			{
				data[i] = this.defaultconfig[i];
			}
		}
		this.currentdata= data;
		this.isactive2=true;
		
		dim = this.dimensions(element);
		
		this.tdiv2.style.position = 'absolute';
		this.tdiv2.style.top  = (dim.y+40)+'px';
		this.tdiv2.style.left = (dim.x-340)+'px';
		this.tdiv2.style.width = 400+'px';
		istyle = 'color:#'+data.fontcolor+';background-color:#'+data.color+';font-size:'+this.config.fontsize+'px;padding-left:2px;padding-right:2px;';
		text = data.text;
		innerhtml = this.drawpointything(data.orientation,400,20);
		innerhtml += _tT.parse('tooltipinside',{style:istyle,color:data.color,text:text});
		
		this.tdiv2.innerHTML=innerhtml;
		this.tdiv2.style.display='block';
		
	}
}
tTooltip.prototype.show = function(element,data)
{
	
	clearTimeout(this.to);
	
	this.checkdiv();
	
	if((typeof element =='object')&&(typeof data =='object'))
	{
		this.currentelement = element
		for (var i in this.defaultconfig)
		{
			if(typeof data[i]=='undefined')
			{
				data[i] = this.defaultconfig[i];
			}
		}
		this.currentdata= data;
		
		this.isactive=true;
		dim = this.dimensions(element);
		
		istyle = 'color:#'+data.fontcolor+';background-color:#'+data.color+';font-size:'+this.config.fontsize+'px;padding-left:2px;padding-right:2px;';
		text = data.text;
		innerhtml = this.drawpointything(data.orientation);
		innerhtml += _tT.parse('tooltipinside',{style:istyle,color:data.color,text:text});
		
		this.tdiv.innerHTML=innerhtml;
		/*this.tdiv.style.display='block';*/
		
	}
}
tTooltip.prototype.hide= function()
{

	
	this.tdiv.innerHTML='';
	//this.tdiv.style.display='none';
	this.isactive=false;
}
tTooltip.prototype.hidesticky= function()
{
	this.tdiv2.innerHTML='';
	this.tdiv2.style.display='none';
	this.isactive2=true;
}
tTooltip.prototype._getElementHeight = function(elem)
{
	var h;
	h = elem.scrollHeight;
	return h;
	if (this.isOpera) { 
		h = elem.style.pixelHeight;
	} else {
		h = elem.offsetHeight;
	}
	return h;


}
tTooltip.prototype._getElementWidth = function(elem)
{
	var w;
	w = elem.scrollWidth;
	return w;
	if (this.isOpera) {
		w = elem.style.pixelWidth;
	} else {
		w = elem.offsetWidth;
	}
	return w;


}
tTooltip.prototype.dimensions = function(el)
{

var dim = new Array();
dim.x = this.getPageOffsetLeft(el);
dim.y = this.getPageOffsetTop(el);
dim.w = this._getElementWidth(el);
dim.h = this._getElementHeight(el);
return dim;


}
tTooltip.prototype.getPageOffsetLeft = function(el){
var x;x=el.offsetLeft;
if(el.offsetParent!=null)x+=this.getPageOffsetLeft(el.offsetParent);
return x;
}
tTooltip.prototype.getPageOffsetTop = function(el){
	var y;y=el.offsetTop;
if(el.offsetParent!=null)y+=this.getPageOffsetTop(el.offsetParent);
return y;
}


_toolTip = new tTooltip({})
_toolTip.init();