var ExpertTooltip = function(){
	this.position = 'right';
    
    this.findOffsetX = function(obj){
        var curleft = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curleft += obj.offsetLeft
                obj = obj.offsetParent;
            }
        }
        else 
            if (obj.x) 
                curleft += obj.x;
        return curleft;
    }
    
    
    this.findOffsetY = function(obj){
        var curtop = 0;
        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else 
            if (obj.y) 
                curtop += obj.y;
        return curtop;
    }
    
    this.show = function(parentElement, contents, marginX, marginY){
        function actualWidth(el){
            if (document.all) 
                return (el.currentStyle['width'.replace(/-/g, '')]).replace('px', '');
            return (document.defaultView.getComputedStyle(el, null).getPropertyValue('width')).replace('px', '');
        }
		
		this.element = document.createElement('div');
        this.element.id = 'expert_tooltip';
        this.element.className = 'expert_tooltip';
		this.element.style.visibility = 'hidden';
        this.element.innerHTML = contents;
		document.body.appendChild(this.element);
        
        // need to fixate default size (MSIE problem)
		if (document.all) {
			this.element.style.width = this.element.offsetWidth + 'px';
			this.element.style.height = this.element.offsetHeight + 'px';
		}
        
        if (typeof parentElement != 'object') 
            parentElement = document.getElementById(parentElement);
        
        // if tooltip is too wide, shift left to be within parent 
        //if (posX + this.element.offsetWidth > parentElement.offsetWidth) 
        //    posX = parentElement.offsetWidth - this.element.offsetWidth;
        //if (posX < 0) 
        //    posX = 0;
        
        if (this.position == 'left') 
            x = (this.findOffsetX(parentElement) + marginX) - actualWidth(this.element);
        else 
            x = this.findOffsetX(parentElement) + marginX;
        y = this.findOffsetY(parentElement) + marginY;
		
        this.element.style.left = x + 'px';
        this.element.style.top = y + 'px';
        
        this.element.style.visibility = 'visible';
    }
    
    this.hide = function(){
        if(this.element) document.body.removeChild(this.element);
    }
}

