ToolTip = function(name, parentDiv, Caption, parentObj) {
	this.name = name;
	this.Caption = Caption;
	this.parentObj = parentObj;
	this.parentDiv = parentDiv;
	this.opacityInterval = null;
	this.interval = 25;
	this.w = null; this.h = null;
	
	// Html elements
	if (document.body.toolTip == null) {
		this.html = new Object();
		this.html.div = document.createElement('div');
		document.body.appendChild(this.html.div);
		this.html.div.style.position = 'absolute';
		this.html.div.style.verticalAlign = 'middle';
		this.html.div.style.textAlign = 'center';
		this.html.div.style.padding = '2px';
		this.html.div.style.fontSize = '11px';
		this.html.div.style.backgroundColor = 'yellow';
		this.html.div.style.border = '1px orange solid';
		this.html.div.style.display = 'none';
		this.style = this.html.div.style;
		document.body.toolTip = this.html;
		this.html.div.userData = new Object();
		//alert('tooltip create!');
	}
	else {
		this.html = document.body.toolTip;
	}
	
	//this.setSize(w, h);
	this.setCaption(this.Caption);	
}

ToolTip.prototype = {
	setCaption : function(sValue){
		this.Caption = sValue;
		this.html.div.innerHTML = this.Caption;
		if (trim(this.Caption) == '') {  this.hidden(); }
	},
	
	getCaption : function(){
		return this.Caption;
	},	
	
	setSize : function(w, h) {
		this.w = w;
		this.h = h;
		this.html.div.style.width  = (this.w != null ? this.w + 'px' : 'auto');
		this.html.div.style.height  = (this.h != null ? this.h + 'px' : 'auto');
	},
	
	getSize : function() {
		return {height: this.h, width: this.w};
	},
	
	setPosition : function(x, y) {
		this.html.div.style.left = x + 'px';
		this.html.div.style.top = y + 'px';
	},
	
	setOpacity : function() {
		this.opacity = this.opacity + this.opacitySum;
		setOpacity(this.html.div, this.opacity);
		if (this.opacity >= 80 || this.opacity <= 0) { this.clearInterval(); }
	},
	
	clearInterval : function() {
		window.clearInterval(this.opacityInterval); this.opacityInterval = null;
	},
	
	show : function() {
		if (this.opacityInterval != null) { return; }
		if (trim(this.Caption) == '') { return; }
		
		this.opacity = 0;
		this.opacitySum = 10; 
		
		setOpacity(this.html.div, 0);
		this.setSize(this.w, this.h);
		this.setCaption(this.Caption);
		
		this.html.div.style.display = 'block';

		if (this.parentDiv != null) {
			this.x = this.getOffsetLeft(this.parentDiv) + 2;
			this.y = this.getOffsetTop(this.parentDiv) + this.parentDiv.offsetHeight + 2;
			this.setPosition(this.x, this.y );
		}
		
		this.html.div.style.zIndex = this.getMaxZIndex() + 1;
		
		if (oBrowserSniffer.isMsie == true && oBrowserSniffer.VersionMajor < 7) {
			setOpacity(this.html.div, 80);

			if (this.tmpIframe == null) {
				this.tmpIframe = document.createElement('iframe');
				document.body.appendChild(this.tmpIframe);
			}			
			this.tmpIframe.style.position = 'absolute';
			this.tmpIframe.style.width = this.html.div.offsetWidth + 'px';
			this.tmpIframe.style.height = this.html.div.offsetHeight + 'px';
			this.tmpIframe.style.left = this.html.div.style.left; 
			this.tmpIframe.style.top = this.html.div.style.top;
			this.tmpIframe.style.display = 'block';
			this.tmpIframe.style.zIndex = (this.html.div.style.zIndex - 1);
			setOpacity(this.tmpIframe, 0);
			return; 
		}

		this.opacityInterval =  window.setInterval(this.name + ".setOpacity();", this.interval);
	},
	
	hidden : function() {
		if (this.opacityInterval != null) { this.clearInterval(); }
		this.html.div.style.display = 'none';
		this.html.div.style.textAlign = 'center';
		if (this.tmpIframe != null) { this.tmpIframe.style.display = 'none'; }
	},
	
	mouseOver : function() {
		this.show();
	},
	
	mouseOut : function() {
		this.hidden();
	},
	
	getOffsetLeft : function(obj) {
		var pos = obj.offsetLeft;
		//if (!isNaN(parseInt(obj.style.borderLeftWidth, 10))) { pos += parseInt(obj.style.borderLeftWidth, 10); }
		while ((obj = obj.offsetParent) != null) {
			pos += obj.offsetLeft;
			if (!isNaN(parseInt(obj.style.borderLeftWidth, 10))) { pos += parseInt(obj.style.borderLeftWidth, 10); }
			
			//TODO:
			if (obj.tagName.toLowerCase() == 'fieldset' && oBrowserSniffer.isFirefox == true) { pos += 2; }
			if (obj.tagName.toLowerCase() == 'fieldset' && oBrowserSniffer.isSafari == false) { pos += 2; }
		}
		return pos;
	},
	
	getOffsetTop : function(obj) {
		var pos = obj.offsetTop;
		//if (!isNaN(parseInt(obj.style.borderTopWidth, 10))) { pos += parseInt(obj.style.borderTopWidth, 10); }	
		while((obj = obj.offsetParent) != null) {
			pos += obj.offsetTop;
			if (!isNaN(parseInt(obj.style.borderTopWidth, 10))) { pos += parseInt(obj.style.borderTopWidth, 10); }
			if (obj.tagName.toLowerCase() == 'fieldset' && oBrowserSniffer.isFirefox == true ) {
				
				for(var i=0;i<obj.childNodes.length;i++){
					if (obj.childNodes[i].nodeName.toLowerCase() == 'legend') {
						pos += obj.childNodes[i].offsetHeight  + 2;
						break;
					}				
				}
				 
			}
		}
		return pos;
	},
	
	getMaxZIndex : function() {
		iMaxZIndex = 0;
		for(var i=0;i<document.body.childNodes.length;i++){
			if (document.body.childNodes[i].style) {
				if (!isNaN(document.body.childNodes[i].style.zIndex)) {
					if (document.body.childNodes[i].style.zIndex > iMaxZIndex) {
						iMaxZIndex = parseInt(document.body.childNodes[i].style.zIndex, 10);
					}
				}
			}
		}
		return iMaxZIndex;
	}	
}
