/*
*Copyright mtr 2008
*/
___jfcBaloons = [];
////////////////////////////////////////////////////////////////////////////////
function initBaloon(){}
function _hideBaloon(){}

function doBaloon( _object, _url, _innerHTML, _align )
{
    var type="";
    var content="";
    if(_url)
        {
          if(typeof(_url)=='object')
                type = 'json';
              else
                  type='url';
          content = _url;
        }
        else
         content = _innerHTML;
    var d = DOMBaloon(_object,content, type )
    d.align(_object,_align);
    return d;
}

function DOMBaloon( _obj, _content, _type )
{
  var uid = ('jfcBalon'+String(Math.random()));
//remember content  
  var URL = _content;
//rpc type  
  if(_type=='url'){
    _content = '<img src="___images/loading.gif" />';
  }  
  
//DOM element
  var db= {
            hideTimeout     :100,
            align           :function( _obj, _type ){
                                _type = _type?_type:'bottom';
                                this.prototype = ___prototype( 
                                  DOMel(this)
                                  ,{ style: Align2Obj( this, _obj, _type) }
                                )
                              },
            destroy         :function(){
                  _clearDestroyTimeout(db);
                  if(db.prototype.parentNode)
                    db.prototype.parentNode.removeChild(db.prototype);
                  delete db;
            },
            setContent      :function( _content ){
                db.prototype.body.prototype = ___prototype(db.prototype.body.prototype,{innerHTML:_content});
            },
            setHideTimeout  :function(_t){
                _clearDestroyTimeout( db )
                db.hideTimeout=_t; 
                _setDestroyTimeout( db );
            },
          
/*################# DOM ######################################################*/      
            className     :'jfcContainer',
            style         :{display:'block',position:'absolute'},
            id            :uid,
            onmouseover:function(){_clearDestroyTimeout( db )},
            onmouseout:function(){_setDestroyTimeout( db )},
            ___jfcChilds  :{
/*
                            shadow  :{
                                className:'jfcShadow',
                                style:{background:'url(___images/shadow.png)',zIndex:0,position:'absolute'}
                            },
*/                
                            body    :{
                                      className:'jfcBaloon',
                                      innerHTML:_content,
                                      style:{zIndex:1}
                            } 
            }
/*############################################################################*/            
  }    
//create DOM element  
  db.prototype = new dEl(document.body,0,db);
 //decrement hierarhy  
  db.prototype = DOMel(db.prototype);
//content -- json  
switch(_type)
{
    case 'json':
      db.prototype.body.prototype = ___prototype(db.prototype.body.prototype,_content);
    break;
    case 'url':
      rpcGet('_hrpcBaloon',db,URL);
    break;
}
//remember DOM elelemnt  
  db.dElement  = DOMel(db);
//align  
  db.align(_obj);
//remember in globals to destroy ability

//_setDestroyTimeout( db );
_obj.onmouseout=function(){_setDestroyTimeout( db );}

___jfcBaloons[db.id]=db;
//nice apear
//opacityApear(DOMel(db));

 return db;
}
//rpc handler
function _hrpcBaloon(_req,_db)
{
  _db.setContent(_req.responseText);
}
function _clearDestroyTimeout( _db )
{
    _db.hTimeout = clearTimeout( _db.hTimeout );
}
function _setDestroyTimeout( _db )
{ 
    _db.hTimeout = _db.hideTimeout?setTimeout( '_hideBaloonO("'+_db.id+'",100)', _db.hideTimeout ):0;
}
function _hideBaloon( _id )  
{
    var baloon = ___jfcBaloons[_id];
    if(baloon)
      baloon.destroy();
}
function _hideBaloonO(_id, o)
{
    _hideBaloon( _id ); 
  var baloon = ___jfcBaloons[_id];
  setOpacity(baloon.prototype ,o);
  if(o>=0)
    setTimeout('_hideBaloonO("'+_id+'",'+(o-30)+')',20);
  else
      {
         _hideBaloon( _id ); 
      }
}



