﻿function tooltip_bubble() {
   this.parentID = null;
   this.title = null;
   this.content = null;  
   this.left = 0;
   
   this._focusHandler = null;
   this._blurHandler = null;
}

tooltip_bubble.prototype = {

    //****Methods
   
   init: function() {
   
        this._focusHandler = Function.createDelegate(this, this._onFocus);
        this._blurHandler = Function.createDelegate(this, this._onBlur);
        
        var e = $get(this.get_parentID());
        $addHandler(e, "focus", this._focusHandler);
        $addHandler(e, "blur", this._blurHandler);
           
   }, 
   
   _onFocus: function() {
   
        var _parentID = this.get_parentID();
        var _content_title = this.get_title();
        var _content_body = this.get_content();
   
        var _bubble = $get(_parentID + '_tooltip_bubble')
        
        var _title, _content;
               
        if( _bubble == null )
        {
            _bubble = document.createElement("div")
            _bubble.id = _parentID + '_tooltip_bubble'
            _bubble.className = "bubble";
            
            var _content_holder = document.createElement("div")
            _content_holder.className = "bubble_content";
            
            var _arrow = document.createElement("div")
            _arrow.className = "arrow";
            
            _content_holder.appendChild(_arrow);

            var _close_button = document.createElement("a")
            _close_button.className = "bubble_close";
            _close_button.href = "javascript:void(0);";        
            _close_button.title = "Close";
            
            _content_holder.appendChild(_close_button);      
            
            _title = document.createElement("span")
            _title.className = "bubble_title";
            _title.id = _parentID + '_tooltip_bubble_title'      
            
             _content_holder.appendChild(_title); 
            
            _content = document.createElement("p");
            _content.id = _parentID + '_tooltip_bubble_content'
            
            _content_holder.appendChild(_content); 
            
            _bubble.appendChild(_content_holder);

            var container = $get(this.get_parentID()).parentNode;
            container.appendChild(_bubble);

        }
        else
        {            

            _title = $get(_parentID + '_tooltip_bubble_title'  )
            _content = $get(_parentID + '_tooltip_bubble_content')        
        }        
            
        if ( _content_title != null ) 
        {                  
            if( Sys.Browser.agent == Sys.Browser.InternetExplorer )
             {
                _title.innerText = _content_title;
             }
             else
             {
                _title.textContent = _content_title;
             }             
         }
        
        
        if( Sys.Browser.agent == Sys.Browser.InternetExplorer )
         {
            _content.innerText = _content_body;
         }
         else
         {
            _content.textContent = _content_body;
         }
        
        /* Put Elements Together */
        
        
       
        /* Determine where to position this element */
        
        var _parent = $get(_parentID)
        var _parent_bounds = Sys.UI.DomElement.getBounds(_parent)
        
        _bubble.style.left = _parent_bounds.x + _parent_bounds.width + this.get_left() + 'px';
        _bubble.style.top = _parent_bounds.y + (-3) + 'px';

   },
   
   _onBlur: function() {
   
        var _parentID = this.get_parentID()
   
        var _bubble = $get(_parentID + '_tooltip_bubble');        
        var _container = _bubble.parentNode;        
        var _removed = _container.removeChild(_bubble);
                
   } ,
    
    
    //**** GET/SET Properties
    get_parentID: function() {
   
        return this.parentID;
    },
    set_parentID: function(parentID) {
        
        this.parentID = parentID;
    },
   
   get_title: function() {
   
        return this.title;
    },
    set_title: function(title) {
        
        this.title = title;
    },
   
   get_content: function() {
   
        return this.content;
    },
    set_content: function(content) {
        
        this.content = content;
    },
   
   get_left: function() {
   
        return this.left;
    },
    set_left: function(left) {
        
        this.left = left;
    }        

}


